Script Valley
Docker: Complete Course
Docker Compose/Assessment

Practice & Assessment

Test your understanding of Docker Compose

Multiple Choice Questions

6
1

In a Compose file, `depends_on: db` ensures what exactly?

2

What command shows the resolved Compose file with all .env variable substitutions applied?

3

You run `docker compose up -d --scale api=3` but get an error about port binding. What is the most likely cause?

4

What happens when both docker-compose.yml and docker-compose.override.yml exist and you run `docker compose up`?

5

Which healthcheck condition should you use in depends_on to ensure Postgres is accepting connections before starting your API?

6

How do you prevent a .env file with real credentials from being committed to version control while still documenting required variables?

Coding Challenges

1
1

Compose stack with health-checked database and API

Write a complete docker-compose.yml for a two-service stack: (1) a PostgreSQL 16 service named 'db' with a named volume for data persistence, POSTGRES_PASSWORD and POSTGRES_DB set via a .env file, and a healthcheck using pg_isready with 5-second interval, 5-second timeout, and 5 retries; (2) a service named 'api' using build: . that depends on db with condition: service_healthy, reads DB_HOST=db and DB_PASSWORD from .env, exposes port 3000, and has restart: unless-stopped. Also write the .env file and a .env.example. Run the stack with docker compose up -d, confirm both containers are healthy with docker compose ps, and stream the logs for the api service. Estimated time: 25 minutes.

Medium

Mini Project

1

Full-Stack Local Development Environment

Build a complete local dev environment using Docker Compose for a React frontend, Node.js API, and PostgreSQL database. Requirements: (1) three services: 'frontend' (React, port 5173), 'api' (Node.js, port 3000), 'db' (PostgreSQL 16). (2) All credentials loaded from a .env file using variable substitution. (3) The api depends on db with service_healthy using a pg_isready healthcheck. (4) Create a docker-compose.override.yml that adds bind mounts to both frontend and api services for hot-reload during development, without modifying the base Compose file. (5) All three services on a single named network so they resolve by service name. (6) A named volume for db data persistence. Run the stack with both files active and confirm frontend can call api (test with curl or browser) and api can query db. Document all override file usage.

Hard
Practice & Assessment โ€” Docker Compose โ€” Docker: Complete Course โ€” Script Valley โ€” Script Valley