Bitpath

Boss lesson · Unit 03

Compose

A web app, a database and a cache described in one file

13 exercisesabout 3 min

What you practise

  • A web app, a database and a cache in one file: services, ports, volumes, environment, start order and health checks

Try a question from this lesson

Pick one

An app needs three containers, a network and a volume: five commands and a dozen flags. A new teammate must get exactly the same setup. What is the most reliable way?

The ideas

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

A Compose file

compose.yaml describes containers as data. Each key under services is one service: a container with a name, and either an image to pull or a build directory with a Dockerfile.

docker compose up -d creates everything in the file. docker compose down stops and removes the containers and their network.

YAML
services:
  web:
    build: .
    ports:
      - "8000:8000"
  cache:
    image: redis:7

Concept

Started is not ready

depends_on makes Compose start one service before another. But it only waits until the container is running, and a database needs a few more seconds before it accepts connections.

A healthcheck is a command Docker runs inside the container again and again. Exit code 0 means healthy.

YAML
services:
  db:
    image: postgres:17
    healthcheck:
      test: ["CMD-SHELL",
             "pg_isready -U postgres"]
      interval: 5s
      retries: 5

10 more exercises in the app

  • 1× match the pairs
  • 1× type the answer
  • 5× multiple choice
  • 1× fill the blanks
  • 1× order the lines
  • 1× true or false

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy