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 →
- How do you check a container's IP address, environment variables and resource usage?
docker inspect shows full JSON details such as IP, env vars, mounts and state, and -f with a Go template pulls out one field. docker stats shows live CPU, memory and network usage.
BeginnerQuick answer1 min read - How do you find out why a Docker container exited immediately?
Run docker ps -a to see its status and exit code, then docker logs for the output. A container lives only as long as its main process, so a quick exit means the process finished or crashed.
BeginnerQuick answer1 min read - How do you view and follow the logs of a running container?
Use docker logs <container>. Add -f to follow new lines, --tail N to show only the last N lines, and --since to limit by time. It shows whatever the main process wrote to stdout and stderr.
BeginnerQuick answer1 min read - What does docker run -d -p 8080:80 --name web nginx do?
It starts a container named web from the nginx image in the background (-d) and publishes container port 80 on host port 8080, so http://localhost:8080 reaches nginx.
BeginnerQuick answer1 min read - What happens when you run docker run nginx and the image is not on your machine?
Docker looks locally, does not find nginx:latest, pulls it from Docker Hub, then creates and starts the container. With no tag given it uses latest, which is just a default tag name, not a guarantee of the newest version.
BeginnerQuick answer1 min read - What is the difference between docker compose stop, down and down -v?
stop halts containers but keeps them. down stops and removes containers and networks. down -v also deletes the named volumes, which destroys stored data.
BeginnerQuick answer1 min read - What is the difference between docker exec and docker attach?
docker exec starts a new process inside a running container, such as a shell. docker attach connects your terminal to the container's existing main process, so exiting it can stop the container.
BeginnerQuick answer1 min read - What is the difference between docker rm, docker rmi and docker system prune?
docker rm deletes containers, docker rmi deletes images, and docker system prune bulk-removes stopped containers, unused networks and dangling images. Add -a for all unused images, and --volumes for unused volumes.
BeginnerQuick answer1 min read - What is the difference between docker stop and docker kill?
docker stop sends SIGTERM so the app can shut down cleanly, then SIGKILL after a 10 second grace period. docker kill sends SIGKILL (or a signal you choose) straight away, with no chance to clean up.
BeginnerQuick answer1 min read - What is the difference between docker compose up and docker compose run?
up creates and starts all services (or those named) as defined, with ports and dependencies. run starts a one-off container for a single service with a command you give, then exits, and does not publish ports by default.
IntermediateQuick answer1 min read