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. Which command stops a running container?

docker end
docker halt
docker kill
docker stopCorrect

docker stop is the polite way to shut a container down: it sends a SIGTERM asking the main process to wrap up gracefully, and only force-kills it after waiting a grace period, unlike docker kill which skips straight to force-terminating.

medium

2. In a docker-compose.yml, the `app` service has `depends_on: [db]`. When you run `docker-compose up`, the app container starts and immediately crashes because it can't connect to the database, even though the db container is also starting. What's the most likely explanation?

By default, `depends_on` only waits for the db container to start, not for the database process inside it to finish initializing and accept connectionsCorrect
Compose starts services in alphabetical order regardless of `depends_on`
`depends_on` is ignored unless the services are on the same custom network
`depends_on` requires both services to define the same HEALTHCHECK instruction, or it has no effect at all

Plain `depends_on` guarantees Compose starts the `db` container before the `app` container, but a database process can take several seconds to initialize after its container starts, so `app` can easily start before `db` is actually ready to accept connections. The fix is `depends_on: db: condition: service_healthy` paired with a `HEALTHCHECK` on the db service, so Compose waits for db to report healthy before starting app. Option D is a trap: a HEALTHCHECK isn't required for basic `depends_on` to work at all, it's only needed if you want the smarter `service_healthy` condition.

hard

3. How does Docker implement process isolation at the kernel level?

Full VM emulation via QEMU
SELinux only
chroot + sudo
Namespaces + cgroupsCorrect

Docker doesn't emulate a separate machine or run a whole second operating system for each container, that's what a full VM does. Instead it isolates processes using the host kernel's own namespaces (controlling what a process can see) and cgroups (controlling what it can use), which is why containers start almost instantly compared to VMs.

easy

4. Which statement about Docker volumes is TRUE?

Volumes are slower than bind mounts
Volumes are managed by the host OS and persist beyond container lifecycleCorrect
Volumes are stored inside the container’s writable layer
Volumes can only be used on Linux hosts

A volume isn't part of the container that created it, it's a separate storage area the Docker daemon itself manages, sitting outside any single container's own writable layer. That separation is exactly why the data in a volume survives even after the container that wrote to it gets removed entirely.

medium

5. What is the effect of HEALTHCHECK instruction in a Dockerfile?

Enables auto-restart on failure
Sets up liveness probes for Kubernetes
Scans the image for vulnerabilities
Adds a command that Docker periodically runs to check container healthCorrect

HEALTHCHECK's job is narrow and specific: run a command on a schedule and use its result to report whether the container is healthy, unhealthy, or still starting up. It doesn't scan for vulnerabilities, auto-restart anything on its own, or configure Kubernetes probes, those are separate, unrelated concerns.

hard

6. You observe cgroup memory limit is set to 512MB, but free -m inside container shows total memory = host RAM. Why?

free reads /proc/meminfo, which reflects host memory; apps should read /sys/fs/cgroup/memory/memory.limit_in_bytesCorrect
cgroup v1 doesn’t support memory limits
Memory limits only apply to disk cache
The container is using host network mode

free reads /proc/meminfo, which isn't aware of cgroups at all, it just reports the HOST's total physical memory regardless of any per-container limit. To see the ACTUAL memory ceiling a container is bound by, an application needs to read the cgroup's own limit file directly instead of relying on tools like free.

easy

7. What does the `docker ps` command show by default?

Currently running containersCorrect
Available Docker networks
All images on the system
All containers, including stopped ones

There's no info here about images or networks, so those two are already off-topic. Stopped containers do exist, but `docker ps` alone won't show them, that requires the `-a` flag. Left with its default, unflagged behavior, `docker ps` lists exactly the containers that are running right now.

medium

8. A Java app in a container with -Xmx512m is killed by OOMKiller at ~600MB RSS. Why?

JVM ignores container limits by default (pre-JDK 10)
-Xmx sets heap only; native memory (Metaspace, threads, direct buffers) adds overhead
Both A and CCorrect
Docker memory limit is not set

-Xmx only caps the JVM's HEAP, it says nothing about all the other memory a JVM process actually uses, metaspace, thread stacks, native buffers, which adds real overhead on top of the heap limit. And older JVMs (before JDK 10) didn't even look at the container's cgroup memory limit at all, both factors together mean actual memory usage can blow right past what -Xmx alone would suggest.

hard

9. What does docker build --secret id=mysecret,src=./secret.txt . do, and what Dockerfile instruction uses it?

Signs the image with a private key
Attaches a secret to runtime; used with ENV
Securely passes a file during build without storing in image; used with RUN --mount=type=secret,...Correct
Encrypts image layers

Normally, anything you copy or reference during a build risks ending up baked into a layer forever, even if you try to delete it afterward. The --secret flag instead makes a file's contents available ONLY for the duration of a single RUN --mount=type=secret step, entirely in memory, so the secret is usable during the build but never actually written into any image layer.

easy

10. What file is used to define a Docker image?

DockerfileCorrect
docker-compose.yml
image.yaml
config.json

A Dockerfile is the actual recipe Docker follows to build an image: a plain text file listing instructions like FROM, RUN, and COPY, executed in order, each one adding a new layer to the resulting image.

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.