Containers are the standard way to package and ship software, so Docker interview questions come up in DevOps engineer, SRE, cloud engineer, platform engineer and backend developer interviews. This guide covers the top 20 Docker interview questions and answers from container basics to image optimization, networking, security and troubleshooting.
Use it alongside Kubernetes preparation, since most interviews connect Docker to orchestration and CI/CD pipelines.
Docker fundamentals
1. What is Docker and how is a container different from a virtual machine?
Docker builds, ships and runs applications in containers. A container shares the host kernel and isolates processes with namespaces and cgroups, so it starts in seconds and uses little memory. A VM runs a full guest OS on a hypervisor, which gives stronger isolation but is heavier.
2. What is the difference between an image and a container?
An image is a read-only template built in layers from a Dockerfile. A container is a running (or stopped) instance of an image with a thin writable layer on top. Many containers can run from the same image.
3. What are the main Docker components?
The Docker CLI, the Docker daemon (dockerd), containerd and runc as the runtime, images, containers, volumes, networks and registries such as Docker Hub, Amazon ECR, Azure Container Registry and Google Artifact Registry.
4. What is the difference between CMD and ENTRYPOINT?
ENTRYPOINT defines the executable that always runs; CMD provides default arguments that can be overridden at docker run. Use the exec (JSON array) form so signals reach your process and it can shut down gracefully.
5. What is the difference between COPY and ADD?
COPY copies local files into the image. ADD can also extract local tar archives and fetch URLs. Prefer COPY for clarity and predictability.
Building better images
6. How do Docker image layers and build cache work?
Each instruction creates a layer. Docker reuses cached layers when instructions and inputs are unchanged. Order the Dockerfile from least to most frequently changing: copy dependency manifests and install dependencies before copying source code, so code changes do not reinstall dependencies.
7. What is a multi-stage build?
A multi-stage build uses several FROM stages: compile and test in a full SDK image, then copy only the build output into a minimal runtime image such as distroless, Alpine or a slim base. The result is a smaller, faster and more secure image.
8. How do you reduce Docker image size?
Use small base images, multi-stage builds, a .dockerignore file, combine and clean up package installs in one layer, avoid installing build tools in the final image, and remove caches. Tools like dive help inspect layers.
9. How do you handle configuration and secrets in containers?
Pass configuration with environment variables or mounted config files. Never bake secrets into images or commit them to Dockerfiles. Use BuildKit secret mounts at build time and a secrets manager, Docker or Kubernetes secrets, or cloud secret stores at runtime.
Storage, networking and Compose
10. What are volumes and bind mounts?
Container filesystems are ephemeral. Named volumes are managed by Docker and are the preferred way to persist data such as databases. Bind mounts map a host path into the container and are handy for local development. tmpfs mounts keep data in memory.
11. Explain Docker networking modes.
Bridge (default, private network on the host with port mapping), host (shares the host network stack), none (no networking), overlay (multi-host networking for Swarm) and macvlan (container gets its own MAC address). User-defined bridge networks provide DNS resolution by container name.
12. What is Docker Compose?
Compose defines multi-container applications in a compose.yaml file: services, networks, volumes, environment and dependencies. docker compose up starts the whole stack, which is ideal for local development and integration testing.
13. Docker Swarm vs. Kubernetes?
Both orchestrate containers. Swarm is simpler and built into Docker but has a smaller ecosystem. Kubernetes is the industry standard with rich scheduling, autoscaling, networking, operators and managed services like EKS, AKS and GKE.
Security and troubleshooting
14. How do you secure Docker containers?
Run as a non-root user, use minimal and trusted base images, scan images with Trivy, Grype or Docker Scout, pin versions and digests, drop Linux capabilities, use read-only filesystems where possible, set resource limits, sign images, and keep the host and runtime patched.
15. A container exits immediately after starting. How do you troubleshoot?
Check docker ps -a for the exit code, read docker logs, inspect the config with docker inspect, and run the image interactively with a shell to test the command. Common causes are a wrong CMD, missing environment variables, a foreground process that ends, or permissions.
16. How do you limit container resources?
Use --memory, --cpus and --pids-limit flags, or resources in Compose and Kubernetes. Without limits one container can starve others on the host. Exit code 137 often means the container was killed for exceeding memory.
17. What is the difference between docker stop and docker kill?
docker stop sends SIGTERM and waits for a grace period before SIGKILL, allowing graceful shutdown. docker kill sends SIGKILL immediately by default.
Scenario questions
18. Scenario: builds in CI are slow. How do you speed them up?
Reorder Dockerfile layers for better caching, use BuildKit with remote cache (registry or GitHub Actions cache), multi-stage builds, smaller contexts via .dockerignore, and parallel builds with buildx. Pin base images so the cache stays valid.
19. Scenario: an app works on your laptop but not in the container. What do you check?
Environment variables, file paths and working directory, missing OS libraries in the slim base image, CPU architecture (arm64 vs. amd64), localhost vs. service-name networking, file permissions for the non-root user, and time zone or locale settings.
20. What is a Docker health check?
A HEALTHCHECK instruction or Compose healthcheck runs a command on an interval to report whether the container is healthy. Orchestrators and depends_on conditions use it to wait for readiness or restart failing containers.
How to prepare for a Docker interview
- Containerize a real app with a multi-stage Dockerfile, a non-root user and health checks.
- Write a Compose file with an app, a database and a cache, and explain the networking.
- Push to a registry from a CI pipeline and scan the image.
- Practice the common debug commands: logs, exec, inspect, stats and events.
Continue with our Kubernetes interview questions, DevOps interview questions and Terraform interview questions.
Frequently asked questions
Is Docker still relevant with Kubernetes?
Yes. Kubernetes no longer uses Docker Engine as its runtime, but Docker remains the most common tool for building OCI images and running containers locally.
What Docker commands should I know for interviews?
build, run, ps, logs, exec, inspect, images, rmi, pull, push, tag, network, volume, compose up/down and system prune.
What Docker questions are asked for experienced engineers?
Image optimization, security hardening, networking internals, build caching in CI, multi-architecture builds and production troubleshooting.
Got the interview? Make sure your resume tells the same story.
Interviewers read your resume right before they talk to you. HiReXL aligns it with the job description’s keywords so your experience and your answers match. HiReXL is built by 4As Consulting, a cloud and DevOps consulting firm. Looking for your next role? Submit your resume for open positions with PanAmerica Inc.


