Linux Labs

Containers: Docker and compose / Stage 8 of 11

docker compose: a stack in one file

Not running Starting usually ~20 s
Leave the lesson

Step 1 of 7 · on a machine · 5 min

The site answers 502

What you will learn

  • Read compose.yaml and find a service's container, environment, ports and volumes in it.
  • Find the failed service of a stack with docker compose ps and the reason in its log.
  • Apply a change to the stack with the right command — up -d or restart — and check the services' health.

A colleague moved the site to docker compose: two containers are described in one file, ~/stack/compose.yaml. The web server proxy takes requests on port 8080 and passes them to the application backend. The colleague brought the stack up with docker compose up -d, which printed no errors, yet the site does not open.

See for yourself. “Start” brings the stack up the way the colleague left it.

Exercise · look

Open the stack's site

The stack in ~/stack is up. Open the site on port 8080 and look at the state of the services.

First, predict

docker compose up -d started both containers without errors. What will the first line of the curl -i answer be?

Now start the exercise, run the command and compare your prediction with the output.

Sign in and start The machine is available after signing in
Check yourself 1 question

What does the (1) in backend's Restarting (1) status mean?

  • The copy number is in the name stack-backend-1. The brackets in the status hold the exit code of the last run.

  • The service has one copy, stack-backend-1 in sudo docker compose ps. The brackets hold the exit code.

  • The status does not show the restart count — sudo docker inspect -f '{{.RestartCount}}' stack-backend-1 does. The brackets hold the exit code, as in Exited (1).

(1) is the exit code of backend's last run: the process ended with an error, and the restart policy starts it again.

Ubuntu 24.04
Loading…