PrepPilotPractise free

Docker interview questions

Images, Dockerfiles, volumes, networks, debugging

14 questions · docker run · updated November 2026

Practise these as flashcards. One or two lines each; the ones you miss come back first.

Start free

Core questions

Container vs virtual machine?

A VM has its own kernel on a hypervisor, takes minutes to boot and is heavier. A container shares the host kernel, isolates processes with namespaces and cgroups, starts in seconds and is much smaller. VMs give stronger isolation; containers are better for packaging and scaling apps.

Image vs container?

An image is the read-only template. A container is a running instance of it with a writable layer. One image can run many containers.

What does -p 8080:80 mean?

Publish the container's port 80 on the host's port 8080. Traffic to host:8080 goes to the container's port 80.

CMD vs ENTRYPOINT?

ENTRYPOINT sets the fixed executable. CMD gives default arguments that docker run can override. Together: ENTRYPOINT is the program, CMD is its default flags.

COPY vs ADD?

COPY copies files from the build context. ADD also unpacks local tar files and can fetch URLs. Prefer COPY because it's predictable.

Intermediate questions

A container exits right after it starts. How do you troubleshoot?

docker ps -a for the exit code, docker logs for the output. Common causes: the main process finished (it must run in the foreground), a bad command or config, a missing env var. Exit 137 means it was killed, often out of memory.

Data disappeared when the container was recreated. Why, and how do you fix it?

Data written inside the container lives in its writable layer, which is deleted with the container. Store it in a named volume or a bind mount instead.

How do you make an image smaller?

Use a slim or distroless base, use multi-stage builds, combine RUN steps and clean package caches in the same step, and add a .dockerignore so you don't copy junk into the build.

Two containers can't reach each other by name. Why?

They're on the default bridge network, which has no name resolution. Put them on a user-defined network (docker network create) and they can find each other by container name.

What restart policies exist?

no (default), on-failure (restart on non-zero exit), always, and unless-stopped (always, unless you stopped it by hand).

What does exit code 137 mean?

The process got SIGKILL, most often from the out-of-memory killer. Confirm with docker inspect (State.OOMKilled) and raise the memory limit or fix the app.

Docker Compose vs Kubernetes?

Compose runs a multi-container app on one host, good for dev and small setups. Kubernetes runs containers across many nodes with scheduling, self-healing, scaling and rolling updates.

Senior questions

How do you secure containers?

See the answer in the app, free

How does a container stay isolated if it shares the kernel?

See the answer in the app, free

More Infrastructure Engineering topics