Advanced Docker Interview Questions and Answers (2027)

48 advanced Docker interview questions with answers: containerd and runc, cgroups, BuildKit cache and secrets, rootless, seccomp, networking, debugging.

Sep 10, 2025 - 14:24
Nov 6, 2026 - 09:07
 0  100
Advanced Docker Interview Questions and Answers (2027)

Advanced Docker interviews test how containers work underneath and how you run them safely in production: namespaces and cgroups, the containerd and runc stack, BuildKit caching and secrets, multi-platform builds, rootless mode, seccomp and capabilities, network drivers, logging, and debugging. This guide has 48 questions with direct answers, grouped by experience level plus scenarios.

This is the internals and production edition of our Docker series. For core concepts start with 100+ Docker interview questions on core concepts; for long troubleshooting stories, use 100+ Docker scenario-based interview questions. OCI and Podman are covered in containerization interview questions, and a short revision list is in 15 most common Docker interview questions.

Key takeaways

  • Be able to explain the request path: docker CLI to dockerd to containerd to a shim to runc, which sets up namespaces and cgroups.
  • BuildKit is the default builder since Docker Engine 23.0. Know cache mounts, secret mounts, multi-stage targets and docker buildx for multi-platform images.
  • Security answers should cover non-root users, rootless mode or user namespace remapping, dropped capabilities, seccomp, read-only filesystems and image provenance.
  • Networking answers should name the drivers (bridge, host, none, overlay, macvlan, ipvlan) and explain embedded DNS on user-defined networks.
  • Senior rounds expect trade-offs: Docker Compose versus Swarm versus Kubernetes, and how images move through CI into ECS or EKS.

Question map

SectionQuestionsFocus
Advanced fundamentals (freshers moving up)1 to 12Internals, layers, storage, PID 1
2 to 5 years13 to 28BuildKit, networking, security, Compose
Senior and architect29 to 40Runtime design, supply chain, orchestration choices
Scenarios41 to 48Production debugging and design

Advanced fundamentals

1. What happens when you run docker run nginx?

The CLI sends an API request to dockerd. If the image is missing, dockerd pulls it from the registry. dockerd asks containerd to create the container; containerd starts a shim process, which calls runc. runc reads the OCI runtime spec, creates namespaces and cgroups, mounts the root filesystem from the image layers, and executes the entrypoint. runc then exits and the shim stays as the container's parent, so containerd and dockerd can restart without killing the container.

2. Which Linux namespaces does a container use?

Docker uses PID (process IDs), NET (network stack), MNT (mount points), UTS (hostname), IPC (shared memory and semaphores) and optionally USER (UID and GID mapping). The cgroup namespace is also used on cgroup v2 hosts. Each namespace gives the container its own view of that resource. Options like --network host or --pid host make the container share the host's namespace instead.

3. What do cgroups do for a container?

Control groups limit and account for resources. Docker uses them for memory limits (--memory), CPU quotas and weights (--cpus, --cpu-shares), PIDs limits (--pids-limit) and block I/O weights. On modern distributions Docker uses cgroup v2, a single unified hierarchy. If a container exceeds its memory limit, the kernel OOM killer stops a process inside it and docker inspect shows OOMKilled: true.

4. How do image layers and the overlay2 storage driver work?

Each filesystem-changing Dockerfile instruction creates a read-only layer identified by a content digest. overlay2 stacks these layers as lower directories and adds a thin writable upper layer per container. Reads come from the topmost layer that has the file; the first write to a lower-layer file copies it up to the writable layer. Layers are shared between images and containers, which saves disk and speeds pulls.

5. Why does deleting a file in a later layer not shrink the image?

Layers are immutable. A deletion in a later layer only adds a whiteout entry that hides the file; the bytes remain in the earlier layer and are still pulled. Remove temporary files in the same RUN instruction that created them, or better, use a multi-stage build so build-time files never reach the final stage.

6. What is the difference between ENTRYPOINT and CMD, and between exec and shell form?

ENTRYPOINT sets the executable; CMD supplies default arguments that docker run arguments replace. Exec form (["app","--flag"]) runs the process directly as PID 1 so it receives signals. Shell form wraps it in /bin/sh -c, so the shell is PID 1 and may not forward SIGTERM, which causes slow, forced stops after the default 10-second timeout.

7. Why does PID 1 matter in a container?

PID 1 gets no default signal handlers from the kernel, so an application that does not handle SIGTERM ignores it. PID 1 must also reap zombie child processes. Use exec form, handle signals in the app, or run with --init, which adds a tiny init (tini) that forwards signals and reaps zombies.

8. Volumes, bind mounts and tmpfs: when do you use each?

Named volumes are managed by Docker under its data directory and are the default for persistent data such as databases. Bind mounts map a host path into the container, which suits local development and host config files but ties the container to host layout. tmpfs mounts live in memory and vanish on stop, useful for secrets or scratch data that should never touch disk.

9. What does a HEALTHCHECK do and what does it not do?

HEALTHCHECK runs a command periodically and sets the container status to healthy or unhealthy. Compose can use it with depends_on: condition: service_healthy and Swarm replaces unhealthy tasks. Plain docker run does not restart an unhealthy container by itself, and Kubernetes ignores Dockerfile HEALTHCHECK in favour of its own probes.

10. What are restart policies?

no (default), on-failure[:max-retries] restarts after a non-zero exit, always restarts on any stop and on daemon start, and unless-stopped is like always but stays stopped if you stopped it manually. Docker applies an increasing delay between restarts to avoid tight loops.

11. What is an image digest and why pin to it?

A digest such as nginx@sha256:... is the content hash of the image manifest. Tags are mutable pointers that can be moved to a new image; a digest always refers to the same content. Pinning digests in production manifests gives repeatable deployments, and tools like Renovate can update them through pull requests.

12. What is a multi-arch image?

It is an image index (manifest list) that points to separate images per platform, such as linux/amd64 and linux/arm64. When you pull, the client picks the matching platform automatically. You build them with docker buildx build --platform linux/amd64,linux/arm64 --push.

Intermediate (2 to 5 years)

13. What does BuildKit add over the legacy builder?

BuildKit builds independent stages in parallel, skips stages the target does not need, supports cache mounts, secret and SSH mounts, cache import and export to registries, multi-platform builds, and attestations such as SBOM and provenance. It is the default builder in Docker Engine 23.0 and later, and docker buildx is its full-featured client.

14. How do cache mounts speed up builds?

A cache mount keeps a directory between builds without putting it in the image layer. Package managers reuse downloads even when the layer itself is rebuilt.

# syntax=docker/dockerfile:1
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN --mount=type=cache,target=/root/.cache/pip \
    pip install -r requirements.txt
COPY . .

15. How do you pass a secret to a build without leaking it?

Use a BuildKit secret mount. The secret is available only during that RUN step and is not written to any layer or the build history. Never use ARG or ENV for secrets, because they are visible in docker history and image metadata.

docker buildx build --secret id=npmrc,src=$HOME/.npmrc -t app:1 .
# Dockerfile: RUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm ci

16. How do you design a multi-stage build for a compiled language?

Build in a full SDK stage, then copy only the binary into a minimal runtime stage such as distroless or scratch. Use --target to build a test stage in CI. The final image has no compiler, package manager or shell, which reduces size and attack surface.

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

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

17. How do you share build cache in CI where runners are ephemeral?

Export and import cache with buildx: --cache-to type=registry,ref=reg/app:buildcache,mode=max and --cache-from type=registry,ref=reg/app:buildcache. GitHub Actions can use type=gha. mode=max caches intermediate stages too, which helps multi-stage builds.

18. How does DNS work on a user-defined bridge network?

Docker runs an embedded DNS server at 127.0.0.11 inside containers on user-defined networks. Containers resolve each other by name and network alias. The default bridge network does not offer this name resolution, which is why Compose creates a project network and why you should not rely on the default bridge.

19. Compare bridge, host, overlay, macvlan and ipvlan drivers.

DriverUse
bridgeDefault single-host network with NAT to the outside
hostShares the host network stack; no port mapping, best raw performance
noneNo networking except loopback
overlayMulti-host networks for Swarm services using VXLAN
macvlanContainer gets its own MAC and appears on the physical LAN
ipvlanLike macvlan but shares the host MAC; useful where switches limit MAC addresses

20. How does port publishing work?

-p 8080:80 makes dockerd add NAT rules (iptables or, in newer releases, optionally nftables) so traffic to host port 8080 reaches container port 80, and may start docker-proxy for some paths. Published ports bypass many host firewall rules in the INPUT chain, so use the DOCKER-USER chain for filtering, or bind to a specific address such as -p 127.0.0.1:8080:80.

21. What Linux capabilities do containers get, and how do you reduce them?

Docker grants a reduced default set (for example CHOWN, NET_BIND_SERVICE, SETUID) and drops powerful ones such as SYS_ADMIN. Harden further with --cap-drop ALL --cap-add NET_BIND_SERVICE or only what the app needs. Avoid --privileged, which grants all capabilities and device access.

22. What is the default seccomp profile?

Docker applies a seccomp filter that blocks dozens of risky system calls, such as those for loading kernel modules or changing the clock. You can supply a stricter custom profile with --security-opt seccomp=profile.json. Running with seccomp=unconfined removes this layer and should be avoided.

23. Rootless mode versus user namespace remapping?

Rootless mode runs dockerd and containers as an unprivileged user, so a container escape lands as that user. User namespace remapping (userns-remap) keeps a root daemon but maps container root to a high, unprivileged UID range on the host. Both reduce impact of an escape; rootless has limits around some networking and storage features. Docs: Rootless mode.

24. Why is mounting /var/run/docker.sock into a container dangerous?

Access to the socket is full control of the daemon, which usually runs as root. A process with the socket can start a privileged container that mounts the host filesystem. Prefer rootless builders, BuildKit in a separate service, or a socket proxy that allows only specific API calls.

25. How do you make a container filesystem read-only?

Run with --read-only and add tmpfs or volumes only for paths that must be writable, such as /tmp or a cache directory. This blocks attackers from dropping binaries into the image filesystem and exposes apps that write to unexpected places.

26. Which logging drivers matter and what is the risk with the default?

The default json-file driver writes to disk on the host with no rotation unless you set max-size and max-file, so busy containers can fill the disk. The local driver rotates by default. Others include journald, syslog, fluentd, awslogs and gcplogs. Set defaults in /etc/docker/daemon.json.

{
  "log-driver": "local",
  "log-opts": { "max-size": "20m", "max-file": "5" }
}

27. What Compose features do experienced users rely on?

Profiles to start optional services, depends_on with health conditions, multiple files or include for overrides, .env interpolation, build targets and secrets, and docker compose watch to sync or rebuild on file changes during development. Compose v1 (docker-compose in Python) reached end of life in 2023; use the docker compose plugin.

28. How do you limit resources and see usage?

Set --memory, --memory-reservation, --cpus and --pids-limit on run, or deploy.resources in Compose. Watch with docker stats, and read raw cgroup files under /sys/fs/cgroup for detail. Always set memory limits on shared hosts so one container cannot starve the rest.

Senior and architect level

29. Why did Kubernetes stop using Docker Engine directly, and does it matter for images?

Kubernetes removed dockershim in version 1.24, so kubelet talks to CRI runtimes such as containerd or CRI-O. Images built with Docker are OCI images and run unchanged. What changes is node-level tooling: use crictl instead of docker ps on nodes. See containerd versus Docker in Kubernetes.

30. How would you build a trusted image supply chain?

Use pinned, minimal base images; build in CI with BuildKit; generate an SBOM and provenance attestation (--sbom=true --provenance=mode=max); scan with Docker Scout, Trivy or Grype; sign with Sigstore Cosign; push to a private registry; and verify signatures at deploy time with an admission policy. Pin deployments to digests.

31. Distroless, Alpine or slim Debian for production?

Distroless has no shell or package manager and the smallest attack surface, but debugging needs ephemeral debug containers. Alpine is small but uses musl libc, which can cause compatibility or performance surprises for some languages. Slim Debian images are larger but compatible and familiar. Choose per language and team debugging skills, and keep the choice consistent.

32. How do you debug a container that has no shell?

Use docker debug where available (Docker Desktop and paid plans), or start a tools container sharing the target's namespaces: docker run -it --pid container:app --network container:app nicolaka/netshoot. On Kubernetes use kubectl debug with an ephemeral container.

33. What happens to running containers when dockerd restarts?

By default containers stop with the daemon. With "live-restore": true in daemon.json, containers keep running while dockerd is down or upgraded, because the shim, not dockerd, is their parent. Live restore is not supported with Swarm mode.

34. Compose, Swarm or Kubernetes for a new platform?

Compose suits local development and single-host apps. Swarm is built into Docker Engine and simple for small clusters, with services, overlay networks and secrets, but its ecosystem is small. Kubernetes has the largest ecosystem and managed offerings (EKS, AKS, GKE) and is the usual choice for multi-team platforms despite higher complexity.

35. How do Swarm secrets and configs differ from environment variables?

Swarm stores secrets encrypted in the Raft log and mounts them into service tasks as files in an in-memory filesystem at /run/secrets/, only for services that are granted them. Environment variables show up in docker inspect, process listings and crash dumps. Configs are the same mechanism for non-sensitive files.

36. How do you run Docker workloads on AWS: ECS or EKS?

ECS is AWS's own orchestrator with task definitions, services and tight IAM integration; with Fargate there are no nodes to manage. EKS is managed Kubernetes, better when you want Kubernetes APIs, Helm and portability. Both pull images from ECR, and both use task or pod IAM roles instead of keys inside images.

37. How do you keep base images patched across hundreds of services?

Maintain a small set of approved base images, rebuild them on a schedule and on new CVEs, publish by digest, and let Renovate or Dependabot open pull requests in service repositories. Scan registries continuously so old images still deployed are flagged.

38. What is the Docker storage and data directory and how do you manage disk?

Docker stores images, containers, volumes and build cache under /var/lib/docker by default (changeable with data-root). Check usage with docker system df, clean with docker image prune, docker builder prune and careful docker system prune. Put the data root on its own volume on production hosts.

39. How would you enforce container security standards on Docker hosts?

Apply the CIS Docker Benchmark, set safe daemon defaults (log rotation, live-restore, userns-remap or rootless, no insecure registries), restrict who can access the socket, run Docker Bench for Security, and scan images in CI. On Kubernetes, enforce the same with Pod Security Admission and policy engines.

40. When would you choose Podman or another runtime over Docker?

Podman is daemonless and rootless by default and integrates with systemd, which fits RHEL environments and locked-down hosts. Docker has a larger desktop and Compose ecosystem. Both produce OCI images. Our containerization post covers Podman in depth.

Scenario questions

41. A container exits with code 137. What do you check?

137 means the process received SIGKILL (128 + 9). Check docker inspect --format '{{.State.OOMKilled}}'. If true, raise the memory limit or fix the leak. If false, someone or something killed it, such as docker stop after the grace period because the app ignored SIGTERM. Exit 143 means it exited on SIGTERM.

42. Builds in CI suddenly take 20 minutes instead of 3. How do you investigate?

Check whether the cache is being imported (look for CACHED steps in the build output). Common causes are a changed early layer such as COPY . . before dependency install, a missing .dockerignore sending a large context, a new runner without registry cache, or a base image tag that moved. Reorder instructions and add cache export.

43. Two containers on the same host cannot reach each other by name.

They are probably on the default bridge network, which has no embedded DNS, or on different networks. Create a user-defined network and attach both (docker network connect), then use container names or aliases. Check docker network inspect for membership.

44. The host disk fills up every week.

Check docker system df and the size of container log files. Usually it is unrotated json-file logs, dangling images from frequent deploys, or build cache. Configure log rotation in daemon.json, schedule docker image prune and docker builder prune --filter until=168h, and alert on disk usage.

45. A security review finds containers running as root. How do you fix it without breaking them?

Add a non-root user in the Dockerfile and set USER, fix file ownership with COPY --chown, move listening ports above 1024 or add only NET_BIND_SERVICE, and make writable paths explicit volumes or tmpfs. Test with --read-only and --cap-drop ALL in staging before rollout.

46. A container is slow to stop and always takes 10 seconds.

The app is not receiving or handling SIGTERM, so Docker waits for the timeout and sends SIGKILL. Switch to exec-form ENTRYPOINT, use exec in wrapper scripts, add --init, or set STOPSIGNAL to the signal the app expects.

47. You must ship one image for x86 servers and ARM-based instances.

Use buildx with QEMU emulation or native ARM builders: docker buildx build --platform linux/amd64,linux/arm64 -t reg/app:1.4 --push .. Cross-compile in the build stage where the language supports it (Go, Rust) to avoid slow emulation, and verify both entries with docker buildx imagetools inspect.

48. Developers need production-like local stacks without leaking production secrets.

Provide a Compose file with profiles for optional services, local mock credentials in a committed .env.example, real secrets only through a secrets manager or Compose secrets from files ignored by Git, and the same images and versions as production pinned by digest.

How to prepare

  • Run docker inspect on a running container and explain every section: State, Mounts, NetworkSettings, HostConfig.
  • Build one image with cache mounts, a secret mount and multi-platform output, then inspect it with docker buildx imagetools inspect.
  • Run a container with --read-only --cap-drop ALL --security-opt no-new-privileges and fix whatever breaks.
  • Read the official docs on BuildKit, networking and Engine security.

Hands-on labs for all of this are part of our Docker training in Kharadi, Pune and live online. Background reading: what Docker is and why it is popular and common Dockerfile mistakes.

FAQ

What counts as an advanced Docker interview question?

Questions on internals (namespaces, cgroups, containerd, runc), BuildKit features, security hardening, networking drivers, logging and storage, supply chain and production debugging, rather than basic commands.

Is BuildKit enabled by default?

Yes. BuildKit has been the default builder for docker build since Docker Engine 23.0, and Docker Desktop uses it as well. docker buildx exposes its advanced options.

What does exit code 137 mean in Docker?

The process was killed with SIGKILL. Check the OOMKilled flag in docker inspect; if it is true the container hit its memory limit.

Do Docker images still work on Kubernetes after dockershim was removed?

Yes. Docker builds OCI images, and containerd and CRI-O run them. Only node-level debugging commands change.

How do I keep secrets out of Docker images?

Use BuildKit secret mounts for build-time secrets and runtime secret stores (Swarm or Kubernetes secrets, cloud secret managers) for runtime. Never use ARG, ENV or COPY for secrets.

Is rootless Docker production ready?

It is supported and documented by Docker, with known limitations around some network and storage features. Test your workloads; user namespace remapping is an alternative when rootless does not fit.

How many questions should I prepare for an advanced Docker round?

Know the 48 here well enough to explain them with a command or example, then practise scenarios from our scenario-based Docker post.

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.