Docker FAQs for Interviews: Quick Answers (2027)

50 frequently asked Docker interview questions with short answers on images, Dockerfiles, volumes, networks, Compose, security and troubleshooting.

Sep 10, 2025 - 13:49
Nov 6, 2026 - 03:01
 0  72
Docker FAQs for Interviews: Quick Answers (2027)

These are the Docker questions interviewers ask most often, answered in two to four sentences each so you can revise them quickly before an interview. The 50 FAQs cover images, Dockerfiles, containers, storage, networking, Compose, security and troubleshooting, grouped from fresher to senior level, with each answer checked against the Docker documentation.

Treat this page as a revision sheet. For full worked problems, use the main set, 100+ Docker scenario-based interview questions. If you are new to containers, read what Docker is and why it is popular in DevOps first. Experienced candidates should also work through 15 common Docker questions for experienced engineers and advanced Docker interview questions.

Key takeaways

  • Most Docker interviews return to the same themes: image versus container, Dockerfile instructions, layers and cache, volumes, networks, Compose and basic security.
  • Exact behaviour is a common trap: docker system prune does not delete volumes unless you pass --volumes, and shell-form ENTRYPOINT ignores CMD.
  • Prefer COPY over ADD, exec form over shell form, non-root users, multi-stage builds and pinned base image tags.
  • Use docker compose (the Compose V2 plugin). The top-level version key in Compose files is obsolete under the Compose Specification.
  • Learn three debugging commands well: docker logs, docker inspect and docker exec.

Topic map

TopicQuestionsLevel
Basics and architecture1 to 10Freshers
Dockerfile and images11 to 22Freshers to mid
Storage and networking23 to 31Mid (2 to 5 years)
Compose, registries and CI32 to 38Mid
Security and production39 to 45Senior
Quick troubleshooting46 to 50All levels

Freshers: basics and architecture

1. What is Docker?

Docker is a platform for building, shipping and running applications in containers. A container packages the app with its libraries and runs as an isolated process on the host kernel, so it behaves the same on a laptop, a CI runner and a server.

2. Container versus virtual machine?

A VM runs a full guest operating system on a hypervisor. A container shares the host kernel and isolates processes with Linux namespaces and cgroups. Containers start in seconds and use less memory; VMs give stronger isolation and can run a different kernel.

3. Image versus container?

An image is a read-only template made of layers. A container is a running (or stopped) instance of an image with a thin writable layer on top. One image can back many containers. Our image versus container guide shows this with examples.

4. What are the main parts of Docker's architecture?

The Docker client (the docker CLI), the Docker daemon (dockerd) that builds and runs containers, containerd and runc underneath for container lifecycle, and registries such as Docker Hub that store images. The client talks to the daemon over a REST API.

5. What is Docker Hub?

Docker's public registry. It hosts official images, verified publisher images and user repositories. Companies often run private registries too, such as Amazon ECR, Azure Container Registry or Harbor. See Docker Hub alternatives.

6. What does docker run do?

It pulls the image if it is missing, creates a container, sets up its network and filesystem, and starts the main process. Common flags: -d (detached), -p 8080:80 (publish port), --name, -e (environment variable), -v (volume) and --rm (remove on exit).

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

stop sends SIGTERM, waits for a grace period (10 seconds by default) and then sends SIGKILL. kill sends SIGKILL immediately unless you choose another signal. Use stop so the app can shut down cleanly.

8. How do you see running and stopped containers?

docker ps lists running containers; docker ps -a includes stopped ones. docker container ls is the newer equivalent.

9. What are namespaces and cgroups?

Namespaces give a container its own view of process IDs, network interfaces, mounts, hostname and users. Cgroups limit and account for CPU, memory and I/O. Together they make a normal Linux process behave like an isolated machine.

10. Is Docker the only way to run containers?

No. Images follow the OCI image specification, so Podman, containerd with nerdctl and Kubernetes runtimes can run them. Kubernetes uses a CRI runtime such as containerd directly rather than the Docker daemon. Our containerization interview questions cover OCI and Podman in depth.

Dockerfile and images

11. What is a Dockerfile?

A text file of instructions (FROM, RUN, COPY, CMD and so on) that docker build executes to produce an image. Each instruction that changes the filesystem creates a layer.

12. CMD versus ENTRYPOINT?

ENTRYPOINT sets the executable; CMD supplies default arguments, or the whole command if there is no entrypoint. Arguments to docker run replace CMD. In exec form they combine: ENTRYPOINT ["python","app.py"] with CMD ["--port","8000"].

13. Exec form versus shell form?

Exec form is a JSON array, such as ["nginx","-g","daemon off;"], and runs the binary directly as PID 1, so it receives signals. Shell form runs through /bin/sh -c. Shell-form ENTRYPOINT also ignores CMD and run arguments, per the Dockerfile reference.

14. COPY versus ADD?

COPY copies files from the build context or another stage. ADD can also fetch URLs, clone Git repositories and extract local tar archives automatically. Use COPY unless you need one of those features, because the extra behaviour can surprise readers.

15. ARG versus ENV?

ARG is available only during the build and is set with --build-arg. ENV persists into the image and running containers. Neither is safe for secrets: build args can appear in image history.

16. What is a multi-stage build?

A Dockerfile with several FROM stages. You compile in a full SDK image and copy only the output into a small runtime image with COPY --from=build. The final image has no compilers or source code.

FROM golang:1.23 AS build
WORKDIR /src
COPY . .
RUN CGO_ENABLED=0 go build -o /app ./cmd/api

FROM gcr.io/distroless/static-debian12
COPY --from=build /app /app
USER nonroot
ENTRYPOINT ["/app"]

17. How does the build cache work?

Docker reuses a cached layer if the instruction and its inputs have not changed. Once one layer changes, every later layer rebuilds. Copy dependency manifests and install dependencies before copying the rest of the source so code edits do not reinstall packages. See ways to speed up Docker builds in CI/CD.

18. What is .dockerignore for?

It excludes files from the build context, such as .git, node_modules, local env files and test output. Builds get faster and secrets stay out of images.

19. How do you make images smaller?

Use multi-stage builds, slim or distroless bases, combine related RUN steps and clean package caches in the same step, and exclude unneeded files. Our image optimization practices go further.

20. What does HEALTHCHECK do?

It defines a command Docker runs periodically to mark the container healthy or unhealthy. Defaults are an interval of 30s, a timeout of 30s, 3 retries and a start period of 0s. Orchestrators can use the status to restart or stop routing traffic.

21. Why should you avoid the latest tag in production?

latest is just a tag that moves. Two deployments a day apart can run different code. Pin a version tag or, better, the image digest (image@sha256:...) for reproducible deploys.

22. How do you pass a secret at build time safely?

With a BuildKit secret mount: RUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm ci, built with docker build --secret id=npmrc,src=$HOME/.npmrc .. The secret is mounted only for that step and is not stored in the image or cache.

2 to 5 years: storage and networking

23. Volume versus bind mount?

A volume is managed by Docker under its data directory and is the preferred way to persist data. A bind mount maps a specific host path into the container; it is handy for local development but ties the container to the host's layout. tmpfs mounts keep data in memory only.

24. What happens to data in the container's writable layer when it is removed?

It is deleted with the container. Anything that must survive goes in a volume or external storage. Our volume management practices cover backups and naming.

25. What does docker system prune remove?

Stopped containers, unused networks, dangling images and unused build cache. It keeps volumes unless you add --volumes, and keeps tagged unused images unless you add -a, per the prune reference.

26. Which network drivers does Docker provide?

bridge (default for standalone containers), host (share the host network stack), none, overlay (multi-host, used with Swarm), macvlan and ipvlan. See the network drivers docs.

27. Why can containers on a user-defined bridge reach each other by name?

User-defined bridge networks provide built-in DNS, so a container named db resolves as db. The default bridge network does not offer name resolution between containers.

28. What is the difference between EXPOSE and -p?

EXPOSE documents which port the app listens on. It does not publish anything. -p host:container actually maps a host port to the container.

29. How do you limit a container's CPU and memory?

With --memory (for example --memory=512m) and --cpus (for example --cpus=1.5). If the container exceeds its memory limit, the kernel's OOM killer stops it and docker inspect shows OOMKilled: true.

30. What restart policies exist?

no (default), on-failure[:max-retries], always and unless-stopped. unless-stopped restarts after daemon restarts unless you stopped the container yourself.

31. How do you copy files in or out of a running container?

docker cp container:/path/file ./file and the reverse. For anything routine, use a volume instead of copying.

Compose, registries and CI

32. What is Docker Compose?

A tool that defines a multi-container application in a YAML file (compose.yaml by default) and runs it with docker compose up. Services, networks and volumes are declared together. Common patterns are in the most used Compose files explained.

33. docker-compose versus docker compose?

docker-compose was the original standalone Python tool (Compose V1). docker compose is the Compose V2 plugin built into the Docker CLI, and it is the one to use now.

34. Does depends_on wait for a service to be ready?

By default it only controls start order. To wait for readiness, give the dependency a healthcheck and use depends_on with condition: service_healthy.

services:
  db:
    image: postgres:16
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 5s
      retries: 10
  api:
    build: .
    depends_on:
      db:
        condition: service_healthy

35. How do you push an image to a private registry?

Log in with docker login registry.example.com, tag the image with the registry path (docker tag app registry.example.com/team/app:1.4.2), then docker push it.

36. What is docker buildx?

The CLI for BuildKit features, including multi-platform builds (--platform linux/amd64,linux/arm64), remote cache export and different builder drivers. It is how you produce one tag that runs on both x86 and ARM.

37. How do you tag images in CI?

Tag with the commit SHA for traceability and a semantic version for releases. Avoid overwriting release tags. Our image tagging guide covers schemes in detail.

38. What does docker init do?

It asks a few questions about your project and generates a starter Dockerfile, compose.yaml and .dockerignore following Docker's recommended practices. Review the output before using it in production.

Senior: security and production

39. Why run containers as non-root?

If an attacker escapes the application, root inside the container is closer to root on the host. Add a USER instruction with an unprivileged user, and consider rootless mode for the daemon itself.

40. What does --privileged do, and why avoid it?

It gives the container almost all host capabilities and device access, removing most isolation. Grant only the specific capabilities needed with --cap-add, and drop the rest with --cap-drop ALL.

41. How do you scan images for vulnerabilities?

Use Docker Scout, Trivy, Grype or your registry's scanner in CI, and fail builds on critical findings that have fixes. Rebuild regularly so base image patches flow in.

42. What is a read-only container filesystem?

Running with --read-only makes the root filesystem immutable, so malware cannot drop files. Mount a tmpfs or volume for paths that must be writable, such as /tmp.

43. How should production containers handle logs?

Write to stdout and stderr and let a logging driver or agent ship them. Configure log rotation for the default json-file driver (max-size, max-file) so logs do not fill the disk.

44. Why does PID 1 matter in containers?

PID 1 must handle signals and reap zombie processes. Many apps do neither. Use exec form so your app is PID 1 and handles SIGTERM, or run with --init to add a small init process.

45. When do you need an orchestrator rather than plain Docker?

When you need scheduling across many hosts, self-healing, rolling updates and service discovery at scale. Plain Docker and Compose suit single hosts and development; see can you use Docker without Kubernetes.

Quick troubleshooting

46. A container exits right after starting. What do you check first?

docker logs <container> and the exit code from docker ps -a. Often the main process finished (for example a service started in the background) or crashed on a missing variable.

47. What do exit codes 137 and 143 mean?

137 is 128 plus 9, meaning SIGKILL, often from the OOM killer or docker kill. 143 is 128 plus 15, meaning SIGTERM, typically a normal docker stop.

48. The app works locally but the port is unreachable from the host. Why?

Either the port was not published with -p, or the app listens on 127.0.0.1 inside the container. Make it bind to 0.0.0.0.

49. How do you get a shell in a running container?

docker exec -it <container> sh (or bash if installed). For minimal images without a shell, use docker debug where available or attach a debug container sharing its namespaces.

50. The disk is full on a Docker host. What do you do?

Run docker system df to see what uses space, then prune unused images, containers and build cache. Check large log files and orphaned volumes before deleting anything that holds data.

How to use this page

  1. Read each question and answer it aloud before looking at the answer.
  2. Mark the ones you got wrong, then run the commands on a test machine.
  3. Move on to scenario practice in the Docker scenario-based questions once you are comfortable here.

For structured labs, the Docker training runs in our Kharadi, Pune classroom and live online.

Frequently asked questions

What Docker questions are asked most in interviews?

Image versus container, CMD versus ENTRYPOINT, COPY versus ADD, volumes versus bind mounts, network drivers, multi-stage builds, Compose, and basic security such as running as non-root.

What is the difference between CMD and ENTRYPOINT?

ENTRYPOINT sets the executable and CMD gives default arguments. Arguments passed to docker run replace CMD but not ENTRYPOINT.

Does docker system prune delete volumes?

No, not by default. It removes stopped containers, unused networks, dangling images and build cache. Add --volumes to also remove unused anonymous volumes.

What does exit code 137 mean?

The container received SIGKILL, often because it hit its memory limit and the OOM killer stopped it, or because someone ran docker kill.

Should I use docker-compose or docker compose?

Use docker compose, the Compose V2 plugin built into the Docker CLI. The older standalone docker-compose tool is Compose V1.

How do I keep secrets out of Docker images?

Use BuildKit secret mounts at build time and runtime secrets from your orchestrator or a secrets manager. Never put secrets in ENV, ARG or copied files.

Are these questions enough for senior roles?

They cover the basics every level is asked. Senior candidates should add scenario and design practice from the advanced and scenario-based Docker posts.

References

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Angry Angry 0
Sad Sad 0
Wow Wow 0
Mridul I am a passionate technology enthusiast with a strong focus on DevOps, Cloud Computing, and Cybersecurity. Through my blogs at DevOps Training Institute, I aim to simplify complex concepts and share practical insights for learners and professionals. My goal is to empower readers with knowledge, hands-on tips, and industry best practices to stay ahead in the ever-evolving world of DevOps.