Docker Compose interview questions

25 questions from the Docker Compose course, each with the correct answer and an explanation. Try to answer before you open the answer.

Compose Fundamentals

1. What is Docker Compose best suited for?

  1. Replacing a database
  2. Training machine learning models
  3. Running multi-container apps for development, testing and simple single-host setups
  4. Managing thousands of nodes
Show answer

Answer: Running multi-container apps for development, testing and simple single-host setups

Compose orchestrates containers on one host.

Lesson: What Docker Compose Is For

2. Which top-level section defines the containers to run?

  1. services
  2. volumes
  3. secrets
  4. x-common-env
Show answer

Answer: services

Each service becomes one or more containers.

Lesson: Anatomy of a Compose File

3. Which command removes containers AND deletes named volumes?

  1. docker compose config
  2. docker compose stop
  3. docker compose ps
  4. docker compose down -v
Show answer

Answer: docker compose down -v

Volumes survive a plain down.

Lesson: The Compose Lifecycle

Defining Services

4. What does build.target select?

  1. The Docker host
  2. A specific stage of a multi-stage Dockerfile
  3. A network
  4. A registry
Show answer

Answer: A specific stage of a multi-stage Dockerfile

Build only the stage you need.

Lesson: image Versus build

5. Does the api service need a published port to reach db?

  1. Yes, always
  2. No, services reach each other by name on the project network
  3. Only on Windows
  4. Only with host networking
Show answer

Answer: No, services reach each other by name on the project network

Publishing is for access from outside.

Lesson: Ports and Exposure

6. What does <<: *common-env do?

  1. Creates a network
  2. Deletes common variables
  3. Starts a new service
  4. Merges the mapping defined by the &common-env anchor into this mapping
Show answer

Answer: Merges the mapping defined by the &common-env anchor into this mapping

Anchors avoid repetition.

Lesson: Environment Variables and YAML Anchors

Interpolation, .env Files and Validation

7. Which wins when a variable is set both in the shell and in .env?

  1. The shell environment
  2. .env
  3. Whichever is longer
  4. Neither; Compose errors
Show answer

Answer: The shell environment

Shell values override .env.

Lesson: Interpolation and the .env File

8. What does ${DB_PASSWORD:?msg} do when DB_PASSWORD is empty?

  1. Uses the word msg as the password
  2. Uses an empty password
  3. Stops loading with the error message
  4. Prompts interactively
Show answer

Answer: Stops loading with the error message

Fail fast on missing configuration.

Lesson: Required Variables

9. A key is in both env_file and environment. Which value does the container get?

  1. Neither
  2. The value from env_file
  3. The value from environment
  4. A random one
Show answer

Answer: The value from environment

Explicit environment wins.

Lesson: Environment Precedence Inside Containers

10. What does docker compose config do?

  1. Resolves, merges and validates the Compose files and prints the result
  2. Starts all containers
  3. Deletes volumes
  4. Pushes images
Show answer

Answer: Resolves, merges and validates the Compose files and prints the result

Validate before you run.

Lesson: Validating With docker compose config

Startup Order, Health and Restarts

11. What does plain depends_on: [db] wait for?

  1. Nothing at all
  2. For the database to accept connections
  3. For a health check to pass
  4. Only for the db container to start, not for the database to be ready
Show answer

Answer: Only for the db container to start, not for the database to be ready

Use condition: service_healthy for readiness.

Lesson: depends_on With Conditions

12. What does a health check enable in depends_on?

  1. Automatic scaling
  2. The service_healthy condition, so dependents wait for readiness
  3. Image building
  4. Port publishing
Show answer

Answer: The service_healthy condition, so dependents wait for readiness

Health checks define readiness.

Lesson: Health Checks

13. Which policy suits a database migration job?

  1. always
  2. no (run once and exit)
  3. unless-stopped
  4. on-failure with infinite retries for a job that succeeds once
Show answer

Answer: no (run once and exit)

Jobs should finish, not restart forever.

Lesson: Restart Policies

Volumes, Bind Mounts and Secrets

14. Which mount type suits PostgreSQL data in Compose?

  1. A tmpfs mount
  2. A bind mount of the source code folder
  3. No mount; keep data in the container layer
  4. A named volume
Show answer

Answer: A named volume

Named volumes persist and are managed by Docker.

Lesson: Named Volumes Versus Bind Mounts

15. Where does a service see a Compose secret?

  1. As a file under /run/secrets/
  2. As a command-line argument
  3. In the image layers
  4. In the Compose project name
Show answer

Answer: As a file under /run/secrets/

Files are safer than environment variables.

Lesson: Secrets as Files

16. What is the safest way to back up PostgreSQL data in Compose?

  1. Rely on docker compose down
  2. Copy the container image
  3. Use pg_dump through docker compose exec and test the restore
  4. Take a screenshot of the data
Show answer

Answer: Use pg_dump through docker compose exec and test the restore

Use database-aware tools.

Lesson: Backing Up and Resetting Data

Networks

17. How does the api service connect to the database in the demo?

  1. By container ID
  2. By the host IP and a published port only
  3. By the hostname db on the project network
  4. It cannot connect
Show answer

Answer: By the hostname db on the project network

Service names are DNS names.

Lesson: The Default Network and Service Names

18. In the demo, can the proxy reach the database directly?

  1. No, they share no network
  2. Yes, all services share one network
  3. Only on port 80
  4. Only if internal is true
Show answer

Answer: No, they share no network

Shared networks define reachability.

Lesson: Custom and Internal Networks

19. Which service should normally publish ports in production?

  1. Internal workers
  2. The database
  3. Every service
  4. The reverse proxy or entry point
Show answer

Answer: The reverse proxy or entry point

Expose the front door only.

Lesson: Exposure and Security

Development, Production and Profiles

20. When is compose.override.yaml loaded?

  1. Only in production
  2. Automatically, unless you pass -f files explicitly
  3. Never; it must be named in every command
  4. Only with --profile override
Show answer

Answer: Automatically, unless you pass -f files explicitly

It exists for local development tweaks.

Lesson: compose.override.yaml for Development

21. Why did port 3000 disappear in the production configuration?

  1. Production disables all ports
  2. The automatic override file is not loaded when -f files are given
  3. The prod file deletes ports explicitly
  4. Port 3000 is reserved
Show answer

Answer: The automatic override file is not loaded when -f files are given

Explicit -f lists replace the default file set.

Lesson: Production Files With -f

22. When does a service with profiles: ["debug"] start?

  1. Only in production
  2. Always
  3. Never
  4. Only when the debug profile is activated
Show answer

Answer: Only when the debug profile is activated

Profiles make services optional.

Lesson: Profiles for Optional Services

Workflows, Limits and a Checklist

23. What is docker compose run --rm useful for?

  1. One-off tasks like migrations or tests in a temporary container
  2. Deleting volumes
  3. Publishing ports permanently
  4. Building the Compose binary
Show answer

Answer: One-off tasks like migrations or tests in a temporary container

Run and clean up.

Lesson: A Smooth Development Workflow

24. What does Compose NOT provide by itself?

  1. Named volumes
  2. Starting several containers
  3. Automatic failover across multiple hosts
  4. Health checks
Show answer

Answer: Automatic failover across multiple hosts

Multi-host resilience needs an orchestrator.

Lesson: Compose in Production and When to Move On

25. Which item belongs on a Compose review checklist?

  1. Commit the real .env with passwords
  2. Publish every database port on all interfaces
  3. Required variables use ${VAR:?message}
  4. Use the latest tag everywhere
Show answer

Answer: Required variables use ${VAR:?message}

Fail fast, expose little, keep secrets out of git.

Lesson: A Compose File Review Checklist

← Back to the course