28 QuestionsDevOps & Cloud
Docker Interview Questions
28 Docker questions from real interviews, sorted by seniority: images and layers, networking, volumes, Compose, security and multi-stage builds.
Images & ContainersLayer CachingVolumes vs Bind MountsMulti-stage BuildsComposeSecurity
Showing 28 of 28 questions
•
#1
What is the difference between an image and a container?
Junior
Junior
| Image | Container | |
|---|---|---|
| What it is | A read-only template | A running instance of one |
| Filesystem | Stacked layers, immutable | Those layers plus a thin writable layer |
| Lifecycle | Built once, reused | Created, started, stopped, removed |
| Analogy | A class | An object |
One image can back a hundred containers, and each gets its own writable layer, so writes inside one are invisible to the others.
The consequence worth stating out loud: anything written inside a container is lost on docker rm unless it was written to a volume or a bind mount. That is what interviewers are checking you understand.
#2
How is a container different from a virtual machine?
Junior
#3
What happens when you run <code class="rounded-none bg-slate-100 px-1 py-0.5 font-mono text-[0.9em] text-slate-900">docker run nginx</code>?
Junior
#4
What is a Docker layer, and why does layer order matter?
Junior
#5
What is the difference between COPY and ADD in a Dockerfile?
Junior
#6
How do you persist data from a container?
Junior
#7
What is a multi-stage Docker build, and what problem does it solve?
Mid
#8
What is the difference between CMD and ENTRYPOINT in Docker?
Mid
#9
Explain Docker's default network drivers and when you would use each.
Mid
#10
Two containers are on the same host but cannot reach each other. How do you debug it?
Mid
#11
What is the difference between a Docker named volume and a bind mount?
Mid
#12
What does <code class="rounded-none bg-slate-100 px-1 py-0.5 font-mono text-[0.9em] text-slate-900">depends_on</code> actually guarantee in Docker Compose?
Mid
#13
How do you make a Docker image smaller?
Mid
#14
A container exits immediately after starting. How do you find out why?
Mid
#15
Why should a container not run as root, and how do you avoid it?
Mid
#16
How do you get a secret into an image without leaking it?
Mid
#17
What is the problem with the Docker <code class="rounded-none bg-slate-100 px-1 py-0.5 font-mono text-[0.9em] text-slate-900">latest</code> tag?
Mid
#18
How does the Docker build cache decide whether a layer can be reused?
Senior
#19
Your image works locally on an M-series Mac and fails on the cluster with "exec format error". What happened?
Senior
#20
Which Linux primitives actually provide container isolation?
Senior
#21
Why does your container take ten seconds to stop, and how do you fix it?
Senior
#22
How do you handle logging for containers, and why not write to a file?
Senior
#23
What is a healthcheck, and where does Docker's version not apply?
Senior
#24
How would you secure a container supply chain end to end?
Senior
#25
<code class="rounded-none bg-slate-100 px-1 py-0.5 font-mono text-[0.9em] text-slate-900">docker system df</code> shows 40 GB reclaimable. Walk through cleaning it up safely.
Senior
#26
Where does Docker Compose stop being the right tool?
Senior
#27
How do you debug inside a container that has no shell?
Mid
#28
What does <code class="rounded-none bg-slate-100 px-1 py-0.5 font-mono text-[0.9em] text-slate-900">.dockerignore</code> do, and why does it matter?
Junior