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 wait blocks until a Compose service has stopped

Docker
~/tips/tip-docker-compose-wait-service

docker compose wait migrate

Make a script wait for a one-shot service to finish before it continues.

A migration or backup service that runs once and exits is easy to start with up -d, but a script also needs to know when it is done. docker compose wait does exactly that.

docker compose up -d migrate
docker compose wait migrate

The command blocks until the containers of the named services stop, then prints their exit codes, so your script can read the result and stop when the migration failed. Leave out the service name and it waits for all of them.

There is also --down-project, which takes down the whole project as soon as the first container stops. I would use that for a test stack: start everything, wait for the test runner, clean up in one go.

It waits for a stop, so on a long running service like a web server it simply hangs. And a service with restart: always or unless-stopped never really stays stopped, so give one-shot jobs restart: "no" (the default). Inside Compose itself, depends_on with condition: service_completed_successfully is the cleaner way to order things; wait is for the script around it.

Further reading: docker compose wait

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