Docker interview questions and answers for developers and DevOps
Docker interview questions test whether you understand what a container really is (an isolated process sharing the host kernel), how images are built from cached layers, and how to run containers safely with the right networking and storage. Expect concept questions, a Dockerfile to write or review, Compose questions, and troubleshooting scenarios such as a container that exits immediately or an image that is far too large. Answers that connect each instruction to build speed, image size or security score best.
By Evin JohnPublished 7 min read
Where Docker questions come up
Docker is tested in DevOps, platform, SRE and backend interviews, and increasingly for any developer who ships services. Developer interviews stay close to writing a good Dockerfile and running a local stack with Compose. DevOps and platform loops go further into image pipelines, registries, security scanning and how containers behave under an orchestrator. Kubernetes questions usually follow Docker ones; they have their own page in Kubernetes interview questions.
- ConceptsWhat a container is, how images and layers work, and how Docker differs from a virtual machine.
- Write or review a DockerfileOften for a Node.js, Python or Java service. Reviewers look at cache order, image size, the user and how the process starts.
- Compose and networkingWire an app to a database, explain service names as hostnames, and persist data correctly.
- TroubleshootingA container that exits with code 137, a port that does not answer, a build that never uses the cache.
Docker fundamentals questions
| Question | What it tests | What a strong answer shows |
|---|---|---|
| What is the difference between an image and a container? | Core model | An image is a read-only template made of layers. A container is a running (or stopped) instance with its own thin writable layer on top. |
| How is a container different from a virtual machine? | Isolation | A container is a process isolated with Linux namespaces and limited with cgroups, sharing the host kernel. A VM runs its own kernel on a hypervisor: stronger isolation, more overhead. |
| Why does Docker on Mac or Windows run a virtual machine? | Platform detail | Linux containers need a Linux kernel, so Docker Desktop runs a lightweight Linux VM. Bind mounts cross that VM boundary, which is why they can be slower there. |
| What is a layer? | Images | Each filesystem-changing instruction adds a layer. Layers are cached and shared between images, and deleting a file in a later layer does not shrink the earlier one. |
| What does EXPOSE do? | Networking | It documents the port the app listens on. Publishing to the host happens with -p host:container at run time. |
| COPY or ADD? | Instructions | COPY copies local files. ADD can also fetch URLs and unpack local tar archives, which is surprising; prefer COPY unless you need that. |
| ARG versus ENV? | Build versus run | ARG exists only during the build. ENV is set in the image and visible to the running container. Neither is a safe place for secrets. |
| What is a registry and what is a tag? | Distribution | A registry stores images (Docker Hub, ECR, GHCR). A tag is a movable label; latest is only a default name, not the newest build. Pin a digest for reproducible deploys. |
What does .dockerignore do? | Build context | Excludes files from the build context, keeping builds fast and keeping .git, local env files and node_modules out of the image. |
| Where do container logs go? | Operations | Whatever the process writes to stdout and stderr is captured by the logging driver and shown by docker logs. Write logs there, not to files inside the container. |
Dockerfile questions
FROM node:22-slim AS build
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
RUN npm run build && npm prune --omit=dev
FROM node:22-slim
WORKDIR /app
ENV NODE_ENV=production
COPY --from=build /app/package.json ./
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist
USER node
EXPOSE 3000
CMD ["node", "dist/server.js"]- Why copy the package files before the rest of the source? The install layer is cached until the lockfile changes. Copying everything first invalidates it on every code edit and reinstalls all dependencies.
- What does a multi-stage build save? Compilers, dev dependencies and build caches stay in the first stage. The final image contains only what runs, so it is smaller and has less to patch.
- CMD versus ENTRYPOINT? ENTRYPOINT sets the executable, CMD supplies default arguments that
docker runcan override. Together they make an image that behaves like a command. - Exec form or shell form? Exec form (
["node", "server.js"]) runs your process directly as PID 1 so it receives SIGTERM. Shell form wraps it in/bin/sh -c, which may not pass the signal on, sodocker stopwaits and then kills it. - Why combine apt-get update and install in one RUN? Separate layers can cache a stale package index. Clean the apt lists in the same RUN so they do not end up in a layer.
- Alpine, slim or distroless? Alpine is tiny but uses musl, which can break prebuilt native modules or change performance. Slim Debian images are a safer default; distroless images have no shell, which helps security and complicates debugging.
- How do you pass a secret during a build without leaving it in the image? BuildKit secret mounts (
RUN --mount=type=secret,...) expose it to one step only. An ARG or ENV ends up in the image metadata or history. - How do you build images for both x86 and ARM?
docker buildx build --platform linux/amd64,linux/arm64produces a multi-architecture image, which matters when developers use Apple silicon and servers run x86.
Networking, storage and Compose questions
| Question | What it tests | What a strong answer shows |
|---|---|---|
| How do two containers talk to each other? | Networking | Put them on the same user-defined network and use the container or service name as the hostname; Docker's embedded DNS resolves it. The default bridge does not offer that name resolution. |
| Bridge, host and none networks? | Network drivers | Bridge gives containers a private network with NAT to the host. Host shares the host's network stack (Linux only in its full form). None disables networking. |
| Volume versus bind mount? | Storage | A volume is managed by Docker and suits databases. A bind mount maps a host path and suits live code in development. tmpfs keeps data in memory only. |
| What happens to data written inside a container when it is removed? | Ephemeral layer | It is lost with the writable layer. Anything that must survive goes to a volume. |
| Does depends_on wait for the database to be ready? | Compose startup | By default it only orders startup. With a health check and condition: service_healthy, Compose waits for the dependency to report healthy. |
| What does a restart policy do? | Resilience | unless-stopped or on-failure restarts the container when it exits. It is not a substitute for an orchestrator across machines. |
| How do you limit a container's memory and CPU? | Resources | --memory and --cpus, enforced through cgroups. Exceeding the memory limit gets the process killed by the kernel. |
services:
api:
build: .
ports:
- "8080:3000"
environment:
DATABASE_URL: postgres://app:app@db:5432/app
depends_on:
db:
condition: service_healthy
db:
image: postgres:17
environment:
POSTGRES_USER: app
POSTGRES_PASSWORD: app
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U app"]
interval: 5s
retries: 10
volumes:
pgdata:Senior Docker and troubleshooting questions
| Scenario | Likely cause | What to say you would check |
|---|---|---|
| The container exits right after it starts. | The main process ended | docker logs on the stopped container and docker inspect for the exit code. A server started in the background, a missing env variable, or a wrong CMD path are common. |
| Exit code 137. | SIGKILL, often out of memory | Check OOMKilled in docker inspect and the memory limit; also a stop that hit the timeout after SIGTERM was ignored. |
| The app works in the container but the browser cannot reach it. | Bind address or port | The app listens on 127.0.0.1 inside the container instead of 0.0.0.0, or the port was not published with -p. |
| Every build reinstalls all dependencies. | Cache busting | A COPY of the whole source before the install step, a changing ARG early in the file, or a build context full of changing files. |
| The image is two gigabytes. | Size | docker image history shows which layer is large. Use a slim base, multi-stage builds, a .dockerignore, and remove caches in the same layer that creates them. |
| The disk on the build server keeps filling up. | Leftover artifacts | Dangling images, stopped containers and build cache. docker system df shows usage; prune on a schedule. |
docker stop always takes ten seconds. | Signals | The process is not receiving or handling SIGTERM. Use exec form, handle the signal in the app, or run a small init with --init. |
- How do you harden a production image? Run as a non-root user, use a minimal base, scan images in CI, sign them, make the root filesystem read-only where possible, and drop Linux capabilities you do not need.
- Why is mounting the Docker socket into a container risky? Whoever controls the socket controls the Docker daemon, which is effectively root on the host.
- How do you get into a running container to debug?
docker exec -it <name> shwhen a shell exists; for distroless images, an ephemeral debug container sharing its namespaces. - How would you speed up CI image builds? BuildKit with a remote cache, ordered layers, a small build context, and cache mounts for package managers.
docker ps -a # include stopped containers
docker logs --tail 100 -f api # follow recent output
docker inspect api --format '{{.State.ExitCode}} {{.State.OOMKilled}}'
docker exec -it api sh # shell inside a running container
docker stats # live CPU and memory per container
docker image history myapp:1.4.2 # which layer is large
docker system df # disk used by images, containers, cacheFictional example
- Interviewer
- Here is a Python service: FROM python, COPY . /app, RUN pip install -r requirements.txt, CMD python app.py. What would you change?
- Candidate
- Four things, in order of impact. First, cache order: copy requirements.txt alone, install, then copy the source, so a code change does not reinstall every package. Second, size: switch to a slim base with a pinned version, add a .dockerignore so .git and local virtualenvs stay out, and install with pip's no-cache option. Third, security: create a user and switch to it before CMD, since the default is root. Fourth, shutdown: use the exec form of CMD so the app is PID 1 and receives SIGTERM on deploys. I would then check the image size and rebuild time before and after to show the change worked.
Docker practice plan
- Days 1 and 2: containerize a small app you know. Measure build time after a one-line code change, then fix the layer order and measure again.
- Days 3 and 4: convert it to a multi-stage build with a non-root user, and compare image sizes with
docker image history. - Days 5 and 6: run it with a database in Compose, add a health check, break the network on purpose and debug it with logs and exec.
- Day 7: practice explaining namespaces, cgroups, exit code 137 and signal handling out loud in under a minute each.
Docker questions sit inside broader loops: DevOps engineer interview questions covers CI/CD and incidents, Kubernetes interview questions picks up where containers meet orchestration, and AWS interview questions covers running containers on ECS, Fargate and EKS.
Troubleshooting answers are judged on the order of your checks, which is easy to lose when you talk. Natively, an AI interview assistant for Mac and Windows, transcribes a mock DevOps round on your computer, so you can read back whether you went to the logs before guessing. In practice it can read a Dockerfile or an error from a screenshot and suggest what to look at, and with Pro or the free trial it can lean on the résumé and job description you add. The transcript and notes are saved for you to review.
Questions people ask
What Docker questions are asked in interviews?
Image versus container, layers and caching, containers versus virtual machines, CMD versus ENTRYPOINT, multi-stage builds, volumes versus bind mounts, container networking, Compose, and how to debug a container that exits.
How do I answer a Dockerfile review question?
Go through cache order, image size, the user the process runs as, how secrets are handled and how the process starts and stops, and say what you would measure before and after each change.
What does Docker exit code 137 mean?
The process was killed with SIGKILL, most often because it exceeded its memory limit or because it ignored SIGTERM and the stop timeout ran out. docker inspect shows whether it was OOMKilled.
Do DevOps interviews ask Docker and Kubernetes together?
Often. Docker questions cover building and running images; Kubernetes questions follow with how those containers are scheduled, exposed, configured and scaled in a cluster.
Where to go next
Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.
Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.
