10 Docker Interview Questions & Answers for DevOps & Cloud Engineers
By Tatiana Mikhaleva Senior Developer Advocate · Docker Captain · CNCF Ambassador · IBM Champion
Prepping for a Cloud or DevOps Engineer interview in 2025? Then you already know Docker is going to show up. It always does. Every single time.
So here are 10 questions you’ll probably get asked, plus how to answer each one without sweating through your shirt. Let’s get you ready, queen. 💪
First, A Quick Refresher: What Is Docker?
Docker is a platform that runs your apps inside isolated little boxes called containers.
The magic part? A container behaves the same no matter where it runs. Your laptop, a test server, production, doesn’t matter. None of that “but it worked on my machine” drama. 😅
And in actual DevOps work, you’ll find it pretty much everywhere: app development, testing, CI/CD pipelines, cloud deployments. The whole pipeline, really.
Question 1: What’s the difference between an image and a container? And what happens if you delete the image?
Okay so think of a Docker image as a frozen recipe for your app. It packs everything the app needs to run, code, libraries, environment settings, all of it.
A container is what shows up when Docker actually cooks that recipe. The recipe becomes a real dish, sizzling on the stove. 🍳
The image stays read-only and you can reuse it as many times as you want. The container, on the other hand, gets its own thin writable layer on top of the image’s layers and runs as an isolated process. Here’s the bit interviewers love: run docker rmi on an image that any container uses, running or stopped, and Docker refuses with a conflict error. The container’s filesystem is built on the image’s layers, and those layers live on disk.
Force it with docker rmi -f my-app:1.2.0 and Docker only removes the tag. The image stays on disk as <none>, because the container still uses it. The container keeps running, and you can stop and start it again. The image is really deleted only once no container uses it.
🚀 Pro Tip:
Tag your images properly (my-app:1.2.0, not just latest) and clean up with docker image prune, which only removes images that no container uses.
Question 2: What actually happens when you run docker run?
When I run docker run, the first thing Docker does is check whether the image is sitting on my machine already.
Nope? Then it pulls the image down from a registry like Docker Hub. After that it spins up a container, which is basically an isolated process with its very own filesystem, networking, and slice of resources.
The isolation itself comes from Linux namespaces and cgroups. That’s the secret sauce.
Then, last step, it fires off whatever default command the image was built to run.
📌 Example:
Running docker run nginx pulls the nginx image (if it’s not local), creates a container, and starts the Nginx server inside that isolated environment.
🚀 Pro Tip:
Use --rm with docker run to automatically clean up the container after it exits — so your system doesn’t get cluttered with stopped containers.
Question 3: COPY vs ADD: what’s the difference, and when would you use each?
Both COPY and ADD move files into your image. So far, twins.
COPYsimply copies files and folders — no surprises.ADDdoes more: it can unpack compressed files like.tar.gzand download files from URLs.
That “extra” behavior from ADD is exactly why I keep my distance. It does things you didn’t always ask for, which makes Dockerfiles harder to read. I reach for COPY by default, and only bring in ADD when I genuinely need one of those tricks.
📌 Example:
# PreferredCOPY ./app /app
# Only if needed (auto-extracts)ADD archive.tar.gz /app/🚀 Pro Tip:
Simplicity is security — prefer COPY unless you have a very good reason.
Question 4: What’s a multi-stage build, and when would you use it?
A multi-stage build just means you’ve got more than one FROM in your Dockerfile. Sounds fancy. It’s not, I promise.
- The first stage does heavy work — installing dependencies, building code.
- The final stage copies only the necessary artifacts into a clean, minimal base image.
The payoff is a lean image. All those build tools and temp files that production never needed? Gone. Left behind in the first stage where they belong.
📌 Example:
# Stage 1 — buildFROM node:22 AS builderWORKDIR /appCOPY package*.json ./RUN npm ciCOPY . .RUN npm run build && npm prune --omit=dev
# Stage 2 — productionFROM node:22-slimWORKDIR /appCOPY --from=builder /app/dist ./distCOPY --from=builder /app/node_modules ./node_modulesCOPY --from=builder /app/package.json ./CMD ["node", "dist/index.js"]🚀 Pro Tip:
Smaller images = faster deployments + fewer vulnerabilities.
Question 5: CMD vs ENTRYPOINT: how do they work together?
ENTRYPOINT is the thing that runs. Your main executable. The star of the show.
CMD hands it the default arguments.
Now the part people trip on. When you call docker run and pass your own arguments, those override CMD. ENTRYPOINT stays put.
Put them together and you’ve got a sensible default that you can still bend at runtime. Best of both, honestly.
📌 Example:
FROM nginx:1.28.0-alpine-slim
ENTRYPOINT ["nginx"]CMD ["-g", "daemon off;"]🚀 Pro Tip:
Want full control at runtime? Use only CMD — and leave out ENTRYPOINT.
Question 6: Volumes vs Bind Mounts: which would you use in production, and why?
For production, I go with Docker-managed volumes every time. They stay tucked away from the host OS, they’re easy to back up, and they hold up nicely over the long haul.
Bind mounts lean on specific host paths. That makes them brittle, and very tied to one machine’s setup. They shine for local dev, though. Just keep them out of production, sis.
📌 Example:
services: db: image: postgres:17 volumes: - pg-data:/var/lib/postgresql/data
volumes: pg-data:🚀 Pro Tip:
Volumes are portable, reliable, and more future-proof across hosts and clusters. And pin the image tag: plain postgres now pulls version 18, which keeps its data in a different path, so this example would break.
Question 7: How does networking between containers work?
Out of the box, Docker drops your containers onto a bridge network and hands each one a private IP.
Catch is, on that default network they can only find each other by IP. Not great. The fix is a user-defined bridge network.
On a user-defined bridge, containers can talk to each other by name. Suddenly service discovery just works, and your life gets so much easier. 💕
📌 Example:
services: app: image: my-app environment: DB_HOST: db DB_USER: appuser DB_PASSWORD_FILE: /run/secrets/db_password secrets: - db_password networks: - app-net
db: image: postgres:17 environment: POSTGRES_DB: mydb POSTGRES_USER: appuser POSTGRES_PASSWORD_FILE: /run/secrets/db_password secrets: - db_password networks: - app-net
secrets: db_password: file: ./db_password.txt
networks: app-net:The password comes from a Compose secret, not from the file itself. More on that in Question 10.
🚀 Pro Tip:
Always use user-defined networks — the default bridge network doesn’t support automatic name-based discovery and can lead to frustrating connection issues.
Question 8: How do you reduce Docker image size, and why should you care?
Smaller images build faster, deploy faster, and give attackers way less to chew on. Win, win, win.
- I start with a minimal base image — like
alpine:3.21.3,python:3.12-slim-bookworm, ornode:22-alpine. - I combine RUN instructions to reduce layers, and clean up any temp files or caches.
- I always use a
.dockerignorefile to exclude things like.git,node_modules, and test data.
And when a build gets gnarly, multi-stage is my go-to. It keeps the build tools out of the final runtime, which is exactly where the bloat usually hides.
📌 Example:
A Node.js app image can shrink from 1.2 GB to under 200 MB by switching to node:22-alpine and cleaning up properly.
🚀 Pro Tip:
Smaller images = faster pipelines, quicker deploys, and fewer security issues.
Question 9: What is BuildKit, and why use it?
BuildKit is Docker’s modern build engine, and it’s a serious step up for performance, security, and flexibility.
It runs independent build steps in parallel, caches way more cleverly, and handles secrets safely while building. It’ll also do multi-platform builds and manage storage efficiently. Lots packed in there.
Good news for most of us: on recent Docker versions BuildKit is already on by default, so there’s nothing to set up. Stuck on something older? You can still switch it on with DOCKER_BUILDKIT=1, or by tweaking the Docker daemon config.
📌 Example:
With BuildKit, multi-stage builds can run steps in parallel, reducing build times significantly.
🚀 Pro Tip:
Lean on BuildKit for builds that are faster, safer, and a whole lot more efficient.
Question 10: How do you handle sensitive data (like secrets) in Docker?
Hardcoding secrets into Dockerfiles or images? Never. Not once. Don’t do it, darling.
Docker has its own tools for this, and a strong answer names them.
At build time, use BuildKit secret mounts. The secret is there for one RUN step and never lands in an image layer:
# syntax=docker/dockerfile:1RUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm cidocker build --secret id=npmrc,src=$HOME/.npmrc .At run time with Compose, declare secrets:. Compose mounts each secret as a file under /run/secrets/, and images like postgres read it through POSTGRES_PASSWORD_FILE (see the example in Question 7).
In production, sample answer: secrets come from a secret manager such as HashiCorp Vault, AWS Secrets Manager, or Kubernetes Secrets, injected at runtime.
Environment variables and a .env file are fine for local runs. Keep .env in .dockerignore so it never sneaks into the image, and remember that environment variables show up in docker inspect.
The rule is simple. Secrets live outside the image, never baked inside it.
📌 Example:
Locally, the database password is a Compose secret read from a file. In production, the same file path is filled by Vault or AWS Secrets Manager.
🚀 Pro Tip:
Good secret management = safer deployments and easier key rotations.
Thanks for reading! Be sure to watch the video version for extra insights and helpful visuals.
Tatiana Mikhaleva
Docker CaptainCNCF AmbassadorIBM Champion
DevOps.Pink — Signal over noise in cloud-native & AI.
I'm a Docker Captain, CNCF Ambassador, IBM Champion, AWS Community Builder and a GitKraken, Cypress, Notion and Platform Engineering ambassador. Vendors don't review my posts; sponsored posts say so at the top. Referral links are labeled as such and earn me a commission.