Home › Interview questions › Docker
Docker Interview Questions & Answers
80 Docker interview questions in 4 levels — junior to senior, plus 19 production scenarios. Read 3 free answers with real-world analogies.
Free sample answers
What is Docker and why do we use it?
One-liner
Docker is a tool that packages an app with everything it needs to run — code, libraries, settings — into one unit called a container, so it runs the same way everywhere.
Real-world analogy
It's like a meal-prep box that comes with the exact ingredients and instructions for one dish. Anyone, anywhere, with the same box gets the exact same meal — no substitutions, no surprises.
Detailed explanation
- Before Docker, 'it works on my machine' was a real problem — an app might depend on specific library versions or settings that only exist on the developer's laptop.
- Docker solves this by packaging the app and everything it depends on into one image, so it behaves the same on a laptop, a test server, and production.
- Containers are lighter than virtual machines because they share the host machine's operating system kernel, instead of each one running a full separate operating system.
Scenario
A developer's app works perfectly on their laptop but crashes on the test server because the server has a different version of a library installed. Packaging the app as a Docker image, with that exact library version baked in, means it behaves identically everywhere it runs.
Best practices
- Don't containerize an app just because it's trendy — for a tiny personal script, it might be unnecessary overhead.
- Learn the difference between an image and a container early — it clears up a lot of confusion later.
- Use official base images from Docker Hub when starting out, rather than building everything from scratch.
What are logging drivers in Docker, and why does the default logging behavior sometimes cause problems?
One-liner
A logging driver controls where a container's output actually gets sent and stored — by default, Docker stores logs as local files, which can grow unbounded and fill up disk space if not managed.
Real-world analogy
It's like a security camera that, by default, just keeps recording to a local hard drive forever without ever archiving or deleting old footage — eventually the drive fills up completely unless someone sets a proper retention policy.
Detailed explanation
- By default, Docker uses the json-file logging driver, which writes everything a container prints to a local file on the host machine, with no automatic size limit unless you configure one.
- Over time, a chatty container (one that logs a lot) can fill up disk space with these local log files if nobody is managing rotation or limits.
- You can configure log rotation (max-size, max-file) to cap how much space logs are allowed to use, or switch to a different logging driver that sends logs somewhere external, like a centralized logging system.
Scenario
A production server unexpectedly runs out of disk space, and investigating shows a single, unusually chatty container has been logging heavily for weeks with no rotation limit set, filling up gigabytes of local log files that nobody was watching. Configuring log rotation limits — and switching to shipping logs to a central logging system instead of just local files — prevents this from happening again.
Best practices
- Always configure log rotation limits (max-size, max-file) for anything running long-term in production — the defaults have no built-in cap.
- For production systems, consider shipping logs to a centralized logging system rather than relying only on local files that are hard to search and easy to lose.
- Periodically check disk usage on machines running containers, especially ones you know are naturally chatty.
A container can't reach the internet, even though the host machine itself has a working internet connection. How do you debug it?
One-liner
This is usually a DNS configuration issue inside the container, or a network mode/firewall setting blocking outbound access — check DNS resolution and the container's network mode before assuming the whole network is broken.
Real-world analogy
It's like a phone that can make calls perfectly fine at home, but suddenly can't get a dial tone from inside a specific room — the phone itself works, so you check that specific room's own wiring and settings rather than assuming the whole phone network has failed.
Detailed explanation
- Test DNS specifically from inside the container (docker exec <container> nslookup google.com or similar) — if DNS resolution fails but a raw IP address works, the issue is DNS configuration, not general connectivity.
- Check which network mode the container is actually running in — a container on an isolated custom network with no proper outbound routing configured can lose general internet access even though the host itself is fine.
- On some systems, host-level firewall rules or corporate proxy settings can block outbound traffic specifically from Docker's own network range, while still allowing normal traffic directly from the host machine itself.
Scenario
A container can reach other containers fine but can't reach the public internet at all. Testing from inside the container shows DNS lookups failing specifically, while a direct IP address actually works fine. It turns out Docker's own DNS settings were pointing to an internal, corporate-only DNS server that isn't reachable from that particular container's network. Explicitly setting a working public DNS server for that container resolves it immediately.
Best practices
- Test both DNS lookup and raw IP connectivity separately when debugging — they can fail independently of each other for different reasons.
- Check your Docker daemon's own DNS configuration if multiple containers are all showing the exact same DNS issue at once.
- Rule out host-level firewall or corporate proxy settings specifically affecting Docker's own network range, not just the host's normal traffic.
A preview of the 80 questions in the Docker guide
Junior (23)
- What is Docker and why do we use it?
- What is the difference between a Docker image and a Docker container?
- What is a Dockerfile and what does it actually do?
- What are image layers, and why do they matter?
+ 19 more Junior questions, with full answers, in the guide.
Mid-level (20)
- What is a multi-stage build, and why would you use one?
- How does Docker's build cache actually decide when to reuse a layer versus rebuild it?
- What are the different Docker network modes, and when would you use each?
- What's the difference between a named volume, an anonymous volume, and a bind mount?
+ 16 more Mid-level questions, with full answers, in the guide.
Senior (18)
- How would you design a container security hardening strategy at an organizational level, beyond just running as non-root?
- How would you design supply chain security for container images across an entire organization?
- How would you design a CI pipeline for building Docker images at scale, across many teams and repositories?
- How would you design a private registry strategy for a large organization with many teams and regions?
+ 14 more Senior questions, with full answers, in the guide.
Scenario (19)
- A container exits immediately after starting, even though the image builds fine. How do you troubleshoot it?
- Your machine says 'no space left on device' even though you haven't installed much. What's usually causing this with Docker, and how do you fix it?
- A container can't reach the internet, even though the host machine itself has a working internet connection. How do you debug it?
- A container writes files that end up owned by root, and your local user on the host machine can't edit them afterward. How do you fix this?
+ 15 more Scenario questions, with full answers, in the guide.
Get the full DevOps / SRE Interview Guide