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)