Docker Compose v5.8.1 was released on 27 November 2026. It’s a patch release, but most of its fixes are in features that teams rely on for safe deploys and CI: pre_stop lifecycle hooks, docker compose up --wait, watch mode, and how Compose decides which project you’re working on.
This guide explains what changed, shows Compose files that use these features correctly, and gives you a quick way to check the fixes on your own machine.
Upgrade and check your version
Docker Desktop ships Compose, so a Desktop update brings the new version once it’s bundled. On Linux with the Compose plugin, update through your package manager or download the binary from the release page. Then confirm:
docker compose version
# Docker Compose version v5.8.1
pre_stop hooks now run before every stop
Compose’s lifecycle hooks let you run a command right after a container starts (post_start) or just before it stops (pre_stop). Because a pre_stop hook runs before the stop signal, it’s the right place for work that needs the app still running: draining a queue worker, flushing a cache, or backing up a SQLite file.
services:
worker:
image: my-org/worker:latest
volumes:
- data:/data
pre_stop:
- command: /app/bin/drain --timeout 20
- command: cp /data/app.db /data/app.db.bak
volumes:
data: {}
In earlier versions, there were cases where the hook didn’t run when you’d expect it to. Three fixes in 5.8.1 address this:
- Run
pre_stophooks before the plan stops a container (#14477). - Run the
pre_stophooks before every stop the plan makes (#14555). Compose’s execution “plan” can stop containers for several reasons, such as recreating a service after a config change. Each of those stops now runs the hook first. - Stop or restart a container whose
pre_stophook can’t run (#14547). Before this fix, a failing hook could get in the way of the stop or restart itself.
Keep in mind what the docs say about limits: pre_stop hooks run when a container is stopped by a command like docker compose down or Ctrl+C. They don’t run if the container exits by itself or gets killed suddenly. So a hook can make shutdown cleaner, but it can’t guarantee that work gets done.
Writing a good pre_stop hook
- Keep it short. If the hook takes longer than your shutdown budget, the deploy feels stuck. Put a timeout inside the hook itself, as in
--timeout 20above. - Make it idempotent. With the 5.8.1 fixes, the hook runs before every stop the plan makes, including recreations. Running it twice must be safe.
- Use
user: rootonly when needed. Hooks can run with different privileges than the container, which is useful for permission fixes but should be used sparingly.
up --wait now waits for every replica
docker compose up --wait starts services and blocks until they’re running and healthy, which makes it handy in CI before running integration tests. 5.8.1 fixes --wait (and the service_completed_successfully dependency condition) so it waits for every replica, not just one (#14523).
That matters if you scale a service:
services:
api:
image: my-org/api:latest
deploy:
replicas: 3
healthcheck:
test: ["CMD", "wget", "-qO-", "http://localhost:8080/health"]
interval: 5s
timeout: 3s
retries: 10
migrate:
image: my-org/api:latest
command: ["./bin/migrate"]
tests:
image: my-org/api-tests:latest
depends_on:
api:
condition: service_healthy
migrate:
condition: service_completed_successfully
In CI:
docker compose up -d --wait api migrate
docker compose run --rm tests
docker compose down -v
With 5.8.1, the first command doesn’t return until all three api replicas report healthy. Before, a test run could start while one replica was still booting, which is a classic cause of flaky integration tests.
watch handles large deletions
docker compose watch syncs file changes into running containers during development. When you deleted many synced paths at once, for example by switching Git branches or wiping a build directory, the delete step could go wrong. 5.8.1 now deletes a large batch of synced paths in several execs (#14528).
services:
web:
build: .
develop:
watch:
- action: sync
path: ./src
target: /app/src
- action: rebuild
path: package.json
If watch used to fail or hang after a git checkout that removed lots of files, retry with 5.8.1.
Clearer project resolution
Pull request #14151 is described as “one project-resolution story”: a single name precedence, no swallowed load errors, and strict service validation. In practice:
- The project name is resolved one consistent way, whether it comes from
-p,COMPOSE_PROJECT_NAME, the top-levelname:in your Compose file, or the directory name. - If your Compose file fails to load, you see the error instead of Compose quietly carrying on.
- Service names you pass on the command line are validated strictly.
The last two can surface problems that were hidden before. If a script runs docker compose up some-service and some-service doesn’t exist in the loaded file, expect an explicit error now. To avoid surprises, set the project name explicitly in shared files:
name: billing
services:
api:
image: my-org/billing-api:latest
Other fixes
- Models: a model written in short form isn’t pulled again on every run (#14532).
- Jobs: an engine endpoint without HTTP/2 is treated as not supporting jobs (#14559).
- OCI: Compose files published as OCI artifacts load directly from cache when possible (#14466).
- API validation: options for Logs, Events, Publish and Down are validated (#14515).
A quick local test for pre_stop
This tiny project shows the hook running before shutdown:
# compose.yaml
services:
demo:
image: alpine:3
command: ["sh", "-c", "trap 'echo got SIGTERM; exit 0' TERM; while true; do sleep 1; done"]
pre_stop:
- command: sh -c "echo pre_stop ran at $$(date) >> /proc/1/fd/1"
docker compose up -d
docker compose stop
docker compose logs demo
docker compose down
The logs should show the pre_stop ran at ... line before got SIGTERM. Writing to /proc/1/fd/1 sends the hook’s output to the main process’s stdout, so it appears in docker compose logs. Note the $$ in the Compose file, which escapes $ so the container’s shell expands date rather than Compose.
Takeaway
Compose 5.8.1 makes shutdown hooks and readiness checks more dependable: pre_stop runs before every stop, --wait waits for every replica, and watch survives big deletions. Upgrade, make your hooks short and idempotent, and set name: in shared Compose files so project resolution is never a guess. The release notes list every change.
