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: docker compose up -d --wait returns when your containers are healthy

Docker
~/tips/tip-compose-up-wait

docker compose up -d --wait

Starts the stack and waits until the containers are running, or healthy when they have a healthcheck.

docker compose up -d returns the moment the containers are started, not when the app inside is ready. A script that runs the next step straight away can hit a database that is still booting.

docker compose up -d --wait

--wait keeps the command open until every service is running. If a service defines a healthcheck, it waits until that check passes. If a container stops or turns unhealthy, the command ends with an error, so a script notices that something went wrong. It also implies -d.

A service that has a healthcheck, as an example:

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

With that in place, docker compose up -d --wait only returns when Postgres accepts connections. --wait-timeout 60 sets how many seconds it waits before it gives up.

Without a healthcheck, --wait only checks that the container is running, which says nothing about whether the app is ready. The flag needs Docker Compose v2.

Further reading: docker compose up reference (Docker docs)

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