# docker & containers
// [25] real interview questions. Answers and sources live in the practice app.
practice this topic- How are containers different from virtual machines?(junior)
- Explain image layers. How does Docker use them when building and running images?(mid)
- Your Docker builds suddenly got slow — the layer cache stopped being hit. How does the build cache work, and what invalidates it?(mid)
- Your application image is 2GB. How do you find out why and shrink it?(mid)
- Explain multi-stage builds. What problem do they solve?(mid)
- What is the difference between COPY and ADD in a Dockerfile? Which should you use?(junior)
- ENTRYPOINT vs CMD — how do they interact, and what's the pitfall with exec form vs shell form?(mid)
- What is the build context, and what is .dockerignore for?(junior)
- Describe in detail what happens when you run `docker run <image>`.(senior)
- True or false: killing the Docker daemon kills all running containers. Explain.(senior)
- Which Linux kernel features make containers possible? Explain namespaces vs cgroups.(mid)
- Container storage is ephemeral. How do you persist data — volumes vs bind mounts, and when do you use which?(mid)
- What container security best practices do you enforce, especially around secrets and privileges?(senior)
- A containerized service crashes occasionally and must come back up automatically. What does Docker offer, and which restart policy do you choose?(mid)
- True or false: pulling an image with the 'latest' tag gives you the most recently published version. Why does this matter in production?(mid)
- What is an image digest, and what problem does it solve that tags cannot?(senior)
- A running container exhibits a bug you want teammates to reproduce, including its current state and debug env vars. How do you share it — and why isn't this how you build production images?(mid)
- Can two containers on the same host talk to each other by default? Explain how Docker networking makes it work — and why user-defined bridges beat the default one.(mid)
- What is the difference between EXPOSE in a Dockerfile and publishing a port with -p?(junior)
- Code inside your container calls an API on the host machine's localhost and gets connection refused. Why, and what are the correct options?(mid)
- Your stack runs happily on Docker Compose. When is Compose genuinely enough, and what concrete signals say it's time for Kubernetes?(senior)
- How do you catch vulnerable packages in your images before they reach production — what does an image scanner actually check, and why is a clean scan not a guarantee?(mid)
- What are rootless containers, what attack do they actually blunt, and what are their practical limitations?(senior)
- A Docker host's disk is nearly full. How do you find what's eating it and clean up safely — and why doesn't removing containers free volume space?(mid)
- Your team wants to run the production PostgreSQL in a container 'like everything else'. Is running stateful services in containers good practice — what actually decides it?(senior)