RMRM Full Stack & AI Engineer · All questions · Roadmaps
DevOps · interview questions

Docker Interview Questions

Docker is a containerization platform that packages applications and their dependencies into lightweight, portable containers. These questions cover core Docker concepts, commands, networking, storage, security, and orchestration basics — spanning beginner to advanced levels.

1. What is Docker and how does it differ from a virtual machine?

beginner

Docker is a platform for packaging and running applications in containers, which share the host OS kernel. Unlike VMs, containers don't need a full guest OS, making them faster to start and much lighter in resource usage.

2. What is a Docker image vs a Docker container?

beginner

An image is a read-only, layered template built from a Dockerfile that defines the application and its dependencies. A container is a runnable instance of an image — a live, isolated process created from that image.

3. What is a Dockerfile and what are its most common instructions?

beginner

A Dockerfile is a text file containing instructions to build a Docker image. Common instructions include FROM (base image), RUN (execute commands), COPY/ADD (copy files), CMD/ENTRYPOINT (default command), EXPOSE (document ports), and ENV (set environment variables).

4. What is the difference between CMD and ENTRYPOINT in a Dockerfile?

intermediate

ENTRYPOINT defines the fixed executable that always runs when a container starts, while CMD provides default arguments that can be overridden at runtime. When used together, CMD supplies default arguments to the ENTRYPOINT command.

5. What is the difference between COPY and ADD in a Dockerfile?

beginner

COPY simply copies files or directories from the build context into the image. ADD does the same but additionally supports extracting local tar archives and fetching remote URLs; best practice is to use COPY unless the extra ADD features are specifically needed.

6. How do Docker layers work and why do they matter for build performance?

intermediate

Each Dockerfile instruction creates a new read-only layer stacked on top of the previous ones; Docker caches these layers. If a layer hasn't changed, Docker reuses the cached version, dramatically speeding up subsequent builds — so ordering instructions from least to most frequently changed is critical.

7. What is a multi-stage build and why would you use one?

intermediate

A multi-stage build uses multiple FROM statements in one Dockerfile, allowing you to compile or build in one stage and copy only the final artifacts into a lean production image. This keeps final images small by discarding build tools, compilers, and intermediate files.

8. What is Docker Compose and when would you use it?

beginner

Docker Compose is a tool for defining and running multi-container applications using a YAML file (docker-compose.yml). It simplifies local development and testing by letting you spin up an entire stack — app, database, cache, etc. — with a single `docker compose up` command.

9. Explain Docker networking modes: bridge, host, and none.

intermediate

Bridge (default) creates an internal private network where containers communicate via IP; containers are isolated from the host network unless ports are published. Host mode removes network isolation so the container shares the host's network stack directly. None disables all networking for the container.

10. What is the difference between a Docker volume and a bind mount?

intermediate

A Docker volume is managed by Docker, stored in Docker's storage area, and is the recommended way to persist data because it is portable and easier to back up. A bind mount maps a specific host filesystem path into the container, giving tighter control but creating host-path dependency.

11. How does Docker handle container isolation under the hood?

advanced

Docker leverages Linux kernel features: namespaces (pid, net, mnt, uts, ipc) to isolate process trees, network interfaces, and filesystems per container; and cgroups to limit and account for CPU, memory, and I/O resources. This provides lightweight isolation without a hypervisor.

12. What is the difference between docker stop and docker kill?

beginner

docker stop sends SIGTERM to the main process, giving it time to shut down gracefully, then sends SIGKILL after a timeout (default 10s). docker kill immediately sends SIGKILL (or a specified signal), forcefully terminating the container without a grace period.

13. How can you reduce Docker image size?

intermediate

Use a minimal base image (e.g., alpine), leverage multi-stage builds, chain RUN commands to reduce layer count, remove caches and temp files in the same layer they are created, use .dockerignore to exclude unnecessary build context files, and avoid installing unnecessary packages.

14. What is a Docker registry and how does image tagging work?

beginner

A Docker registry is a storage and distribution system for images (e.g., Docker Hub, AWS ECR). Tags are labels appended to an image name (image:tag) to identify versions; if omitted, latest is used by default. You push/pull images using the full reference: registry/repository:tag.

15. What are Docker secrets and why are they preferred over environment variables for sensitive data?

advanced

Docker secrets store sensitive data (passwords, tokens) in an encrypted, in-memory tmpfs file inside the container rather than in environment variables. This prevents secrets from appearing in docker inspect output, image layers, or shell history, reducing the attack surface.

16. What is the difference between EXPOSE in a Dockerfile and publishing a port with -p?

intermediate

EXPOSE is documentation only — it records which port the containerized application listens on but does not actually publish it to the host. The -p (or --publish) flag in docker run creates a host-to-container port mapping, making the port accessible from outside the container.

17. How do you ensure containers restart automatically and what are the available restart policies?

intermediate

You set a restart policy with --restart when running a container. Options are: no (default, never restart), on-failure[:max-retries] (restart on non-zero exit), always (always restart, including on daemon start), and unless-stopped (always restart except when explicitly stopped by the user).

18. What is the difference between Docker Swarm and Kubernetes?

advanced

Docker Swarm is Docker's native clustering and orchestration tool — simpler to set up and good for smaller workloads. Kubernetes is a more powerful, feature-rich orchestration system with advanced scheduling, auto-scaling, and a large ecosystem, making it the industry standard for large-scale production deployments.

19. How would you debug a container that exits immediately after starting?

intermediate

First run docker ps -a to find the container and check its exit code. Then use docker logs <container_id> to inspect stdout/stderr output. You can also override the entrypoint with docker run --entrypoint sh -it <image> to get an interactive shell and investigate the environment directly.

20. What is a distroless image and what are its security benefits?

advanced

A distroless image contains only the application runtime and its dependencies — no shell, package manager, or standard Linux utilities. This drastically reduces the attack surface because an attacker who compromises the container has no tools to explore or escalate, and there are far fewer OS-level CVEs to patch.

Practice these out loud with an AI interviewer that grills you and grades your answers.
Open the app — free to start

© RM Full Stack & AI Engineer · All interview questions · Roadmaps · Open the app