You had better know this!
- Mark Kendall
- Oct 16
- 4 min read
Here are 25 senior-level Docker interview questions with tight, real-world answers you can use to score them quickly (ballpark = partial credit; fumbling = fail).
š³ 25 Docker Interview Questions + Answers (Senior-Level)
1. Whatās the difference between an image and a container?
Answer:
An image is a read-only blueprint with instructions (filesystem + metadata). A container is a running instance of that image ā itās mutable, has its own process space, and can be started/stopped/destroyed independently.
2. How does Docker isolate processes?
Answer:
Through Linux namespaces (PID, NET, IPC, MNT, UTS) for isolation and cgroups for resource limits (CPU, memory). Combined, they create lightweight virtualization.
3. What is a Docker layer and why is it important?
Answer:
Each instruction in a Dockerfile creates a layer. Layers are cached, shared, and only rebuilt when they change ā improving build speed and image efficiency.
4. Explain the difference between
ENTRYPOINT
and
CMD
.
Answer:
ENTRYPOINT defines the main executable; CMD provides default arguments.
CMD is overridden by command-line arguments, but ENTRYPOINT runs every time unless replaced with --entrypoint.
5. How do you reduce Docker image size?
Answer:
Use minimal base images (e.g., alpine), combine RUN commands, clean caches, use .dockerignore, and prefer multistage builds to copy only compiled artifacts.
6. What happens internally when you run
docker run
?
Answer:
Docker pulls the image (if not local), creates a container filesystem, assigns a network namespace and IP, sets up volumes, then executes the containerās command via the runtime (runc/containerd).
7. Whatās the role of
docker-compose.yml
?
Answer:
Defines multi-container applications ā services, networks, volumes ā allowing you to bring up an entire stack with docker-compose up.
8. How do you persist data between container restarts?
Answer:
Use volumes (managed by Docker) or bind mounts (host path). Volumes are better for portability and lifecycle control.
9. How would you inspect whatās inside a running container?
Answer:
docker exec -it <container> /bin/bash for shell access,
docker logs, docker inspect, or docker top to view configuration, logs, and processes.
10. Whatās the difference between a bridge, host, and overlay network?
Answer:
bridge: default network for standalone containers on one host
host: removes network isolation; uses hostās stack
overlay: spans multiple hosts; used by Swarm/Kubernetes for service networking
11. Whatās the difference between
COPY
and
ADD
?
Answer:
COPY just copies files.
ADD can also extract tar files and fetch remote URLs ā discouraged unless you need that behavior.
12. How do you troubleshoot a container that wonāt start?
Answer:
Use docker logs <id>, docker inspect <id> for error details, check entrypoint/command syntax, environment variables, image versions, or dependency services.
13. Whatās the purpose of
.dockerignore
?
Answer:
Excludes unnecessary files (e.g., node_modules, .git) from build context to speed up builds and reduce image size.
14. What is the difference between
docker stop
and
docker kill
?
Answer:
stop sends SIGTERM (graceful), then SIGKILL after timeout.
kill sends SIGKILL immediately ā no cleanup.
15. Whatās a multistage build?
Answer:
Technique to build and package in separate stages ā e.g., build code in one stage, copy binaries into a slim runtime image ā minimizing final image size.
16. How do you share data between containers?
Answer:
By mounting the same volume into multiple containers, or through Docker networks for communication over TCP/HTTP.
17. How would you secure Docker in production?
Answer:
Run as non-root, use signed images, scan images for CVEs, enable user namespaces, limit capabilities (--cap-drop), and enforce read-only filesystems.
18. Whatās the difference between Docker and a virtual machine?
Answer:
Docker containers share the host OS kernel (lightweight), while VMs emulate hardware and run full guest OS instances (heavier).
19. How can you view the layers of an image?
Answer:
docker history <image> or docker inspect <image> to see the layer chain and commands used to build it.
20. Whatās the difference between
docker build
and
docker create
?
Answer:
build compiles an image from a Dockerfile.
create makes a stopped container from an image (without running it).
21. How do you pass environment variables into containers?
Answer:
Using -e VAR=value flags, --env-file, or in docker-compose.yml via environment: section.
22. How do you limit container resources?
Answer:
Flags like --memory, --cpus, --cpu-shares use cgroups to enforce CPU/memory quotas.
23. Explain image tagging and versioning.
Answer:
Images are tagged as repository:tag. latest is default but not fixed ā use semantic versions (e.g., v1.2.3) for immutability.
24. How do you handle secrets in Docker?
Answer:
Avoid ENV or ARG in Dockerfiles. Use Docker Swarm secrets, AWS Secrets Manager, or mount secrets from external stores as volumes.
25. How do you integrate Docker into a CI/CD pipeline?
Answer:
Use docker build, docker push, and deploy via Compose, Swarm, or Kubernetes. Most pipelines (GitLab CI, Jenkins) run containerized builds for reproducibility.
ā Scoring Guide (C+ and Above)
A (90ā100%) ā Confident, concise, and explains reasoning behind answers (namespaces, layers, etc.)
B (80ā89%) ā Knows the right answer but misses some depth
C (70ā79%) ā Knows usage but canāt explain internals
Below C ā Hesitant, confused, or relying on guesses ā not senior level

Comments