Interview Q&A / Docker & Kubernetes
Docker & Kubernetes interview questions
Images, containers, Dockerfiles, pods and deployments, from first principles.
Prefer rapid revision? Practise Docker & Kubernetes short interview answers →
- Why does localhost inside a container not reach a database running on your laptop?
Inside a container, localhost means the container itself, not the host. To reach a host service use host.docker.internal (Docker Desktop, or with --add-host on Linux), or put both on a Docker network and use the service name.
IntermediateQuick answer1 min read - Why is running a container as root dangerous even though it is isolated?
Root inside a container is still UID 0 on the shared host kernel. A kernel bug, a bad mount or extra capabilities can let an attacker turn that into host access. Running as non-root removes much of that risk.
IntermediateQuick answer1 min read - Why should you create a user-defined bridge network instead of using the default one?
On a user-defined bridge, containers resolve each other by name through Docker's built-in DNS, and you get better isolation. On the default bridge you must use IP addresses or legacy links.
IntermediateQuick answer1 min read - You created an Ingress but nothing works. What could be missing?
Usually no Ingress controller is installed, so no one reads the rules. Also check ingressClassName, that the backend Service and port exist, DNS pointing to the controller's address, and that Pods are ready.
IntermediateQuick answer1 min read - Your Docker image is 1.5 GB. How would you reduce its size?
Use a smaller base image, a multi-stage build, a .dockerignore, install only production dependencies, chain and clean package installs in one RUN, and inspect layers with docker history or dive to find the heavy ones.
IntermediateQuick answer1 min read - How do you run optional services or multiple replicas of a service in Docker Compose?
Assign a service to a profile so it starts only when requested with --profile. For replicas use docker compose up --scale web=3, which requires the service not to publish a fixed host port.
AdvancedQuick answer1 min read - How would you back up the data in a Docker volume?
Run a temporary container that mounts the volume and a host folder, then tar the volume contents into the host folder. Restore by extracting that archive into a volume.
AdvancedQuick answer1 min read