Boss lesson · Unit 03
Compose
A web app, a database and a cache described in one file
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?
Correct answer
One file in the repo that describes the whole setup
Why
Commands in a message go stale and get mistyped. A file is versioned with the code and run by a tool, the same way every time. One image with three programs gives up on updating or restarting them separately.
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.
services:
web:
build: .
ports:
- "8000:8000"
cache:
image: redis:7Concept
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.
services:
db:
image: postgres:17
healthcheck:
test: ["CMD-SHELL",
"pg_isready -U postgres"]
interval: 5s
retries: 510 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.