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 →
- Does EXPOSE in a Dockerfile make a port reachable from outside?
No. EXPOSE is only documentation of the port the app listens on. To make it reachable from the host you must publish it with -p, or -P to publish all exposed ports to random host ports.
BeginnerQuick answer1 min read - What is a .dockerignore file and why do you need it?
A .dockerignore lists files and folders excluded from the build context sent to the Docker daemon. It speeds up builds, keeps secrets and node_modules out of the image, and avoids needless cache invalidation.
BeginnerQuick answer1 min read - Why do Dockerfiles chain commands with && in one RUN instruction?
Each RUN creates a layer, and deleting files in a later layer does not shrink the image. Chaining install and cleanup in one RUN means the temporary files never get stored in any layer.
BeginnerQuick answer1 min read - Why should you pin the base image version in a Dockerfile?
FROM python without a version or with latest can change between builds, so a rebuild may break or introduce new vulnerabilities. Pinning a specific tag or digest gives repeatable builds you update on purpose.
BeginnerQuick answer1 min read - Why use WORKDIR instead of RUN cd in a Dockerfile?
WORKDIR sets the working directory for all later instructions and the running container, and creates it if missing. RUN cd only affects that single RUN line, because each RUN starts a fresh shell.
BeginnerQuick answer1 min read