This chapter is a challenge. One project, ~/signup, is a Flask app and a Postgres database run with Compose. It is broken in several ways. Each lab fixes part of it with skills from chapters 1-8. The lessons say where to look, not what to type.
The first step is a survey. Change nothing until you know which service fails and why.
1. Read README.md, compose.yaml, Dockerfile, .env what should run
2. State docker compose ps -a what does run
3. Logs docker compose logs [SERVICE] why it stopped
4. Config docker compose config what Compose resolved
5. Save docker compose logs > file evidence for laterWhat each command answers
| Question | Command |
|---|---|
| What does "working" mean here? | cat README.md |
| Which services exist, which ports, which env? | cat compose.yaml |
| Which containers ran, which exited, with what code? | docker compose ps -a |
| What did one service print? | docker compose logs web |
What does Compose actually use after .env? | docker compose config |
| What is inside the built image? | docker image history signup-web |
Read the state
cd ~/signup
docker compose ps -aThis is the target, the stack as it looks once this chapter is done:
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
signup-db-1 postgres:16 "docker-entrypoint.s…" db 4 seconds ago Up 4 seconds (healthy) 5432/tcp
signup-web-1 signup-web "python app.py" web 2 seconds ago Up 2 seconds 0.0.0.0:8000->5000/tcpFor a stopped container, STATUS reads Exited (N) with its exit code. COMMAND is the command the container ran. PORTS is empty for a container that is not running, so read the intended ports from compose.yaml.
Read the logs
Only the last lines of a crashed service usually matter. The first error is the one to fix. A later error may only appear once the first is gone.
docker compose logs web
docker compose logs db | tail -5Compare config with code
Wrong values often sit in two files that disagree. Note each pair:
| In compose.yaml | Compare with |
|---|---|
ports: "HOST:CONTAINER" | The port the app listens on (app.py, EXPOSE) |
DB_HOST | The service names under services: |
${VAR} | The keys in .env |
volumes: | Where the image keeps data (docker image inspect) |