brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: add --wait to docker compose up and let it tell you when the stack is really ready

Docker
~/tips/compose-up-wait

docker compose up --wait

Gives your prompt back only when every container in the stack is really up and healthy.

I like commands that answer a question I keep asking. docker compose up -d returns the moment the containers are started, which says nothing about whether the database is ready or the app is answering. So I would add one flag and stop guessing.

The Docker docs describe --wait as waiting for services to be running or healthy, and it implies detached mode, so you do not need -d next to it. Compose only gives your prompt back once everything is up. If a container exits or fails its healthcheck, the command fails too, with a non-zero exit code you can use in a script.

docker compose up --wait
docker compose up --wait --wait-timeout 120

The second line sets a maximum number of seconds to wait, so a stuck stack does not hang forever. The docs do not give a minimum Compose version, so if the flag is unknown, update Compose first.

For a service without a healthcheck, “healthy” can only mean “running”. The flag gets much more useful when the important containers define one. This is the shape from the Compose file reference:

services:
  app:
    image: myapp
    depends_on:
      db:
        condition: service_healthy
  db:
    image: postgres:18
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 10s
      timeout: 5s
      retries: 5

The pg_isready test is my own example for Postgres; check the healthcheck command your image’s docs recommend. With service_healthy, Compose starts the app only after the database passes its check.

A healthcheck only proves what it tests. A container can be healthy and still be showing an error page. I would use this for update scripts and for the moment after a reboot, and still open the app once. Run docker compose ps afterwards to see the health column per service.

Further reading: Docker docs: docker compose up, Docker docs: Compose file reference, services (healthcheck, depends_on), On this site: docker compose run –rm gives you a one-off command that cleans up after itself, On this site: docker compose logs –since 10m shows only what just happened, On this site: Guide: make Docker Compose wait until the database is really ready, not just started

More Docker tips ONBUILD RUN /usr/local/bin/python-build --dir /app/src SHELL ["/bin/bash", "-c"] docker commit <container> myname/testimage:version3 docker import /path/to/exampleimage.tgz docker compose events All Docker tips (192) All topics

Link