I wanted to practise for the CKA without internet and without
installing Kubernetes tools on my Windows laptop either. The answer: one Ubuntu
container on Docker Desktop that holds everything (Docker, kubectl, minikube, yq)
and runs a minikube cluster inside it. After the first start it works fully offline.
It sounds simple. It took me around six attempts and more than an hour. This post gives you the working setup first, and the lessons learned at the end.
How it fits together
Windows + Docker Desktop (WSL2)
└── cka-lab container (Ubuntu 24.04, --privileged)
├── dockerd (Docker-in-Docker)
└── minikube node container
└── containerd → kube-apiserver, etcd, scheduler, ...
Minikube uses its docker driver: the Kubernetes "node" is itself a container, started
by the Docker daemon that runs inside the cka-lab container.
The files
Two files: a Dockerfile and an entrypoint.sh.
Dockerfile
The image installs the base tooling you also find in the exam environment, Docker Engine,
kubectl, minikube and yq, and creates a normal user dev (minikube refuses to run
the docker driver as root).
FROM ubuntu:24.04
ARG KUBECTL_VERSION=v1.34.1
ARG MINIKUBE_VERSION=v1.36.0
ARG YQ_VERSION=v4.45.1
ENV DEBIAN_FRONTEND=noninteractive LANG=C.UTF-8 LC_ALL=C.UTF-8
RUN apt-get update && apt-get install -y --no-install-recommends \
bash-completion ca-certificates curl wget git jq man-db vim less procps \
iproute2 iputils-ping dnsutils netcat-openbsd openssh-client sudo tzdata \
unzip gnupg lsb-release iptables \
&& rm -rf /var/lib/apt/lists/*
# Docker Engine (Docker-in-Docker)
RUN install -m 0755 -d /etc/apt/keyrings \
&& curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
| gpg --dearmor -o /etc/apt/keyrings/docker.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" \
> /etc/apt/sources.list.d/docker.list \
&& apt-get update && apt-get install -y --no-install-recommends \
docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin \
&& rm -rf /var/lib/apt/lists/*
RUN curl -fsSLo /usr/local/bin/kubectl "https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl" \
&& curl -fsSLo /usr/local/bin/minikube "https://storage.googleapis.com/minikube/releases/${MINIKUBE_VERSION}/minikube-linux-amd64" \
&& curl -fsSLo /usr/local/bin/yq "https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64" \
&& chmod +x /usr/local/bin/kubectl /usr/local/bin/minikube /usr/local/bin/yq
# User dev (UID 1000) with sudo and docker access
RUN groupadd -f docker \
&& if id -u ubuntu >/dev/null 2>&1; then userdel -r ubuntu; fi \
&& useradd -m -s /bin/bash -u 1000 -G sudo,docker dev \
&& echo "dev ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/dev
# Exam-like conveniences
RUN echo 'alias k=kubectl' >> /home/dev/.bashrc \
&& echo 'source <(kubectl completion bash)' >> /home/dev/.bashrc
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN sed -i 's/\r$//' /usr/local/bin/entrypoint.sh && chmod 0755 /usr/local/bin/entrypoint.sh
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["/bin/bash"]
The sed strips Windows line endings. If you edit entrypoint.sh on Windows, a CRLF
file fails with a confusing "no such file or directory".
entrypoint.sh
The entrypoint prepares cgroups for nesting, picks the storage driver, starts the Docker
daemon and opens a shell as dev.
#!/usr/bin/env bash
set -e
# cgroup v2 nesting for Docker-in-Docker (Docker Desktop / WSL2)
if [ -f /sys/fs/cgroup/cgroup.controllers ]; then
mkdir -p /sys/fs/cgroup/init
for proc in $(cat /sys/fs/cgroup/cgroup.procs); do
echo "$proc" > /sys/fs/cgroup/init/cgroup.procs 2>/dev/null || true
done
sed -e 's/ / +/g' -e 's/^/+/' /sys/fs/cgroup/cgroup.controllers \
> /sys/fs/cgroup/cgroup.subtree_control || true
fi
# overlay needs /var/lib/docker on a real filesystem (a volume), not overlayfs
mkdir -p /var/lib/docker /etc/docker
FSTYPE="$(stat -f -c %T /var/lib/docker)"
echo "/var/lib/docker filesystem: $FSTYPE"
if [ "$FSTYPE" = "overlayfs" ]; then
echo "WARNING: no volume on /var/lib/docker; falling back to vfs (minikube will fail)."
echo '{ "storage-driver": "vfs" }' > /etc/docker/daemon.json
else
rm -f /etc/docker/daemon.json # let dockerd choose
fi
dockerd > /tmp/dockerd.log 2>&1 &
for i in $(seq 1 30); do
docker info >/dev/null 2>&1 && { echo "Docker daemon is ready."; break; }
sleep 1
done
docker info >/dev/null 2>&1 || { tail -n 100 /tmp/dockerd.log; exit 1; }
exec su - dev
Build and run
Build the image (PowerShell, in the folder with both files):
docker build -t cka-lab .
Run the container. The two volumes matter, more on that below:
docker run -it --privileged --name cka-lab --hostname cka-lab `
-v cka-lab-home:/home/dev `
-v cka-lab-docker:/var/lib/docker `
cka-lab
The first line printed should be /var/lib/docker filesystem: ext2/ext3. If it says
overlayfs, the volume is missing.
Start minikube
Inside the container, as dev. The first start needs internet once. It downloads the
node image, the Kubernetes binaries and the control-plane images:
minikube start --driver=docker --container-runtime=containerd --cpus=2 --memory=4096
kubectl get nodes
* Enabled addons: storage-provisioner, default-storageclass
* Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
Pull the images you practise with while you are still online, so they are cached in the node:
minikube image pull nginx
minikube image pull busybox
Daily use, offline
minikube stop # before leaving
docker start -ai cka-lab # (PowerShell) back into the container
minikube start # resume, no internet needed
Everything lives in the two volumes, so even docker rm cka-lab followed by a new
docker run with the same volumes gives you your cluster back. To start over completely:
minikube delete --all, or remove the volumes with
docker volume rm cka-lab-home cka-lab-docker.
And for real nodes: Azure
Minikube is one node, cheap and offline, perfect for daily practice of pods, deployments, services, RBAC, network policies and storage. For tasks that need real nodes (kubeadm, cluster upgrades, etcd backup and restore, more than one node) I use a 2-node cluster on Azure VMs that a script builds for me. The scripts are on GitHub, and I wrote about them in Yes, I did it! and CKA prep update: 3 hours optimizing my lab, 3 minutes for my first exercise.
Lessons learned
It took six attempts. These are the ones worth knowing:
1. --privileged is required. An ordinary container cannot run a Docker daemon.
Without it, dockerd fails on cgroups, mounts or iptables.
2. The volume on /var/lib/docker is the key. A container's filesystem is overlayfs.
If /var/lib/docker sits on it, Docker inside has to build overlayfs on top of
overlayfs, which the kernel does not allow. The symptoms change with each layer:
failed to mount ... fstype: overlay ... err: invalid argument
driver not supported: overlay2
failed to convert whiteout file "usr/local/.wh..wh..opq": operation not supported
A Docker volume is a plain ext4 directory in WSL2, so overlay works again at every layer.
3. "Use the vfs storage driver" only moves the problem. That is the usual tip for
Docker-in-Docker, and it does make the inner dockerd start. But minikube's node runs
its own container runtime on top, which still needs overlay, so the error just shows up
one layer deeper, during minikube start. vfs is also slow and copies every image layer
in full (it disables minikube's preload). The volume fixes the cause instead.
4. Use containerd as the runtime. With the default Docker runtime, minikube restarts
Docker inside the node (sudo systemctl restart docker), which failed in this nested
setup. With --container-runtime=containerd that step is gone, and containerd with
crictl is what the exam clusters use anyway.
5. Read the real error, not the summary. kube-apiserver is not healthy after 4m0s
looked like a Kubernetes problem. The actual cause was a few lines earlier: an image that
could not be unpacked.
More CKA lab posts
- CKA practice lab in the browser: a real Ubuntu terminal with simulated kubeadm and kubectl, for safe repetition. The story behind it is in From cheat sheets to practice labs.
- k8s-whizlabs-sandbox: the scripts that build a two-node cluster on Azure VMs in a sandbox.
- Preparing for the Certified Kubernetes Administrator (CKA): where this series started.