DevLearningTools

LEARN · DOCKER · PRACTICE

24 Docker Practice Questions

Three levels, running your first container to multi-container Compose setups and Docker in an automated test pipeline. Pick a question, run it in a free online playground, no local Docker install required.

</>

Open a Docker Playground

Run your solutions in a real Docker environment, free, with a Docker Hub account.

Open Play With Docker ↗

Opens a third-party Docker playground in a new tab. External site terms and privacy policy apply.

Level 1 · Images and Containers

Q1–8

Running, inspecting, and cleaning up containers and images.

01

Run Your First Container

Pull the official nginx image and run it as a container, mapping port 8080 on your host to port 80 in the container.

02

Running vs All Containers

Show only currently running containers, then show every container on the system including stopped ones.

03

Exec Into a Running Container

Open an interactive shell inside a running container without stopping it.

04

Inspect a Container's IP

Find a running container's internal IP address using docker inspect.

05

Remove Every Stopped Container

Clean up every stopped container on your system in a single command.

06

Tag and Push an Image

Tag a locally built image and push it to a registry under your own username.

07

Compare Image Sizes

Pull both the full and -alpine variant of the same image (for example node vs node:alpine) and compare their sizes.

08

Image vs Container, With a Real Example

Explain, with a concrete example, the actual difference between a Docker image and a container built from it.

Level 2 · Dockerfiles, Volumes, Networking, and Troubleshooting

Q9–16

Building images correctly and diagnosing what goes wrong at runtime.

09

Write a Minimal Dockerfile

Write a Dockerfile that runs a simple Node.js app on port 3000, copying only package.json first so dependency installs are cached correctly.

10

Multi-Stage Build

Write a multi-stage Dockerfile that builds a Go binary in one stage and copies only the compiled binary into a minimal final image.

11

Persist Data With a Volume

Run a PostgreSQL container with a named volume so its data survives a container restart.

12

Bind Mount for Local Development

Run a container that mounts your local project folder into the container, so code changes reflect without rebuilding the image.

13

Two Containers, One Network

Create a user-defined bridge network and connect two containers so they can reach each other by container name.

14

Diagnose a Container That Keeps Restarting

A container keeps exiting immediately after starting. Describe the exact commands you'd use to find out why.

15

Find What's Eating Disk Space

List Docker's disk usage by category (images, containers, volumes, build cache) and reclaim the unused space.

16

Port Already in Use

A container fails to start because a port is already bound on the host. Show how to find out what's using it and resolve the conflict.

Level 3 · Compose and Real-World Scenarios

Q17–24

Multi-container applications, and Docker in an automated testing pipeline.

17

Write a Basic Compose File

Write a docker-compose.yml running a web app and a Postgres database, with the web app waiting for the database to actually be ready.

18

Scale a Service

Using Docker Compose, scale a worker service to 3 replicas with a single command.

19

Environment-Specific Compose

Describe how you'd structure Compose files to run different configurations for development versus production.

20

Compose Healthcheck

Add a healthcheck to a Compose service so dependent services only start once it's actually ready, not just started.

21

Run Tests Inside a Container in CI

Describe how you'd run an automated test suite inside a Docker container as part of a CI pipeline, and why that's more reliable than running it directly on the CI runner.

22

Ephemeral Test Database

Explain how you'd spin up a disposable database container for an automated test run, guaranteeing it's cleaned up afterward even if the tests fail.

23

Isolated Network for a Test Run

Two services need to talk to each other during automated tests, but shouldn't be reachable from outside the test run. Design the Compose setup for that.

24

One Image, Many Environments

Explain how the exact same Docker image used for automated testing can also be the one deployed to production, and why that consistency matters.

HOW TO PRACTICE
  • Write the actual Dockerfile, Compose file, or CLI command, don't just describe what you'd do.
  • Test what happens when something goes wrong too, a missing port mapping, a container that exits immediately, not just the happy path.
  • Where a question asks you to explain a design decision, write the real tradeoff, not just one answer.