Docker & Containers — Level by Level›Level 2 · Cheat sheet & self-check

Level 2 — Docker Compose · wrap-up

Cheat sheet & self-check

9 questions across 2 lessons. Each answer links back to the lesson it came from.

Pick an answer to see if you got it, and why.

  1. Q1. In a Compose project, how does the api service reach the db service?

    Show answer

    B. Compose creates a network per project and every service is reachable by its service name through Docker's embedded DNS.

    From lesson 04 · Docker Compose basics
  2. Q2. What does `docker compose down` remove by default?

    Show answer

    B. Volumes are kept so your data survives. Add -v to delete them too, and --rmi to remove images.

    From lesson 04 · Docker Compose basics
  3. Q3. What is the difference between `docker-compose` and `docker compose`?

    Show answer

    B. Compose v1 (Python, docker-compose) reached end of life in 2023. Compose v2 ships as a Docker CLI plugin and is invoked as docker compose.

    From lesson 04 · Docker Compose basics
  4. Q4. Where does Compose read ${POSTGRES_VERSION} from when the file says image: postgres:${POSTGRES_VERSION}?

    Show answer

    B. Variable substitution happens on your machine when Compose reads the file: shell environment first, then the project's .env file. Check the result with docker compose config.

    From lesson 04 · Docker Compose basics
  5. Q5. You changed the api image tag in compose.yaml. What makes the change take effect?

    Show answer

    B. restart just restarts the existing container with its old config. up -d compares the desired config with what's running and recreates changed services.

    From lesson 04 · Docker Compose basics
  6. Q6. api starts before PostgreSQL accepts connections and crashes. What fixes the ordering?

    Show answer

    B. Plain depends_on waits only until the db container has started, not until Postgres is ready. A healthcheck plus condition: service_healthy waits for readiness.

    From lesson 05 · Compose for real environments
  7. Q7. What does the restart policy unless-stopped do?

    Show answer

    B. unless-stopped restarts after crashes and after a host reboot, but respects a manual docker stop.

    From lesson 05 · Compose for real environments
  8. Q8. Why use Compose secrets instead of environment: DB_PASSWORD=...?

    Show answer

    B. Environment variables are visible in docker inspect, in /proc/<pid>/environ and are often logged by crash handlers. File-based secrets keep the value out of all of those; many images accept *_FILE variables for this.

    From lesson 05 · Compose for real environments
  9. Q9. You want a pgAdmin container only when debugging, not in normal runs. Which feature fits?

    Show answer

    B. Services with a profile start only when that profile is enabled with --profile debug (or COMPOSE_PROFILES).

    From lesson 05 · Compose for real environments