Back to sections

Docker Quiz

Test what you actually know about Docker. Free sample questions below, from easy to hard, with instant explanations.

easy

1. Why use multi-stage builds?

To increase security by adding layers
To reduce final image size by discarding build-time dependencies (e.g., JDK, npm)Correct
To parallelize builds
To enable live debugging

Compiling an app often needs a whole toolchain (a JDK, npm, build tools) that you don't actually want sitting in your final production image. Multi-stage builds let you use all that tooling in an early, throwaway stage, and then copy over ONLY the finished output into a clean final stage, so the final image ships without any of the bulky build-time dependencies.

medium

2. Which reduces image size more: alpine or distroless?

distroless (2MB static)Correct
Same
Depends on app
alpine (5MB)

Alpine is genuinely small, but it's still a real, complete minimal Linux distribution with its own package manager and shell. Distroless strips even further, down to essentially just your app and its runtime dependencies with nothing else, which is why it typically ends up smaller still.

hard

3. A container with --memory=512m and --memory-swap=512m is killed at 512MB RSS. Why no swap?

memory-swap = memory + swap; setting equal disables swapCorrect
swappiness is 0
Host has no swap configured
Docker ignores swap on cgroup v2

--memory-swap doesn't set the swap amount on its own, it sets the COMBINED ceiling of memory PLUS swap together. Setting it exactly equal to --memory leaves zero room left over for swap, which is why the container gets OOM-killed the instant its actual RAM usage (RSS) hits that same 512MB number, there was never any swap headroom to fall back on.

easy

4. Which command removes all unused images, containers, volumes, and build cache?

docker system prune
docker cleanup
docker system df
docker system prune -aCorrect

Plain system prune only clears out DANGLING images (ones with no tag pointing to them at all), it deliberately leaves alone any image that's still tagged, even if nothing is using it. Adding -a extends the cleanup to ALL unused images, tagged or not, which is why it removes so much more.

medium

5. What is the effect of USER 1000 in a Dockerfile?

Breaks volume permissions
Changes the build-time user only
Requires sudo inside container
Runs container as UID 1000 (non-root), improving securityCorrect

USER 1000 changes who the container's processes actually run AS once it's running, from the default root down to an unprivileged UID. That's a real security improvement since a compromised process now has far less it's actually allowed to do on the system.

hard

6. docker pull registry.internal.example.com/app:latest works fine on an engineer's laptop but fails in the CI pipeline with 'Error response from daemon: pull access denied ... unauthorized: authentication required'. The image name and tag are correct. What is the most likely cause?

The image was deleted from the registry between the laptop pull and the CI run, which always produces this specific error message
The latest tag is reserved and cannot be pulled from private registries, only from Docker Hub
CI runners cannot pull images over HTTPS by default and must be reconfigured to use HTTP
The engineer's laptop has cached registry credentials from a previous docker login in ~/.docker/config.json, but the CI runner has no such credentials, so it needs its own authenticated login, or an equivalent credential or secret configured, before pullingCorrect

docker login stores an auth token scoped to the machine it ran on, typically in ~/.docker/config.json, so a developer's laptop being logged in has no bearing on whether the CI runner, a completely separate environment, is authenticated. The fix is to run docker login, or configure an equivalent credential helper or secret, as an explicit pipeline step before pulling from the private registry. Option B is a distractor because a deleted image typically produces a 'not found' style error rather than an authorization error, and options C and D describe restrictions that don't actually exist in Docker.

easy

7. What does HEALTHCHECK do?

Sends metrics to Prometheus
Scans image for CVEs
Auto-restarts unhealthy containers
Runs a command periodically to determine container health (status: healthy/unhealthy)Correct

HEALTHCHECK tells Docker to run a specific command inside the container on a recurring schedule and use its result to decide whether the container counts as 'healthy' or 'unhealthy', it's a status check, not a vulnerability scanner, an auto-restarter, or a metrics exporter on its own.

medium

8. A Dockerfile contains `ARG API_KEY` and uses it during the build with `RUN curl -H "Authorization: $API_KEY" ...`. The image builds successfully, but when a teammate runs the resulting container and execs in to check `echo $API_KEY`, it's empty. Why?

curl does not have permission to read build-time arguments, so the request silently failed and the container never actually started correctly
ARG values are stripped from the image for security reasons, but should still show up if --build-arg was passed to docker run too
The build cache reused an old layer that never received the ARG value
ARG values are only available during the build process; they aren't persisted into the final image's runtime environment unless separately declared with ENVCorrect

ARG defines a build-time-only variable, useful for things like a version number or a temporary credential needed during the build, but Docker deliberately does NOT carry it into the running container's environment. If the value is also needed at runtime, it must be explicitly bridged with `ENV API_KEY=$API_KEY` in the Dockerfile. Option B is a common misconception: build args aren't restored at runtime by passing a flag to `docker run`, that flag doesn't even exist for `run`, only for `build`.

hard

9. What does --security-opt seccomp=profile.json with "defaultAction": "SCMP_ACT_ERRNO" do?

Allows all syscalls
Blocks all syscalls not explicitly allowedCorrect
Logs syscalls only
Disables seccomp

SCMP_ACT_ERRNO as the DEFAULT action flips the whole model to deny-by-default: instead of allowing everything except a blocklist, the container can ONLY make the syscalls explicitly listed as allowed, and anything not on that list gets blocked outright rather than silently permitted.

easy

10. In a Dockerfile, what does the EXPOSE instruction do?

Automatically publishes ports
Opens ports on the host machine
Configures firewall rules
Documents which ports the container listens onCorrect

EXPOSE is purely a note left for humans and tooling, 'hey, this app listens on this port', it doesn't actually open anything on the host, configure a firewall, or publish the port itself. Actually making a port reachable from outside still requires the -p flag when you run the container.

Ready for the real thing?

Take the full timed Docker quiz and see your score.

    Welcome to OpsQuiz!

    Real scenario-based DevOps questions, hands-on practice, and clear explanations for every answer.