Restarting a container to pick up a new image is fast, but the usual docker compose down && docker compose up -d routine takes your service offline while the new image downloads and the app boots. If you want to update docker containers without downtime, flip the order: pull the new images while the old containers are still serving traffic, then recreate them one at a time. This guide shows the exact commands, how to add healthchecks so replacements only take over when ready, a rolling-update trick for a single VPS, and how to avoid the database migration trap that ruins more updates than bad images do.
How to update docker containers without downtime with docker compose
The core workflow is two commands, in this order. If your compose file is still new to you, read the compose file basics first, and make sure you have compose installed by following the docker compose install guide for Ubuntu 24.04.
cd /srv/myapp
docker compose pull
docker compose up -d
Two details matter. First, docker compose up -d on its own downloads nothing; it recreates containers only from images already on disk. Running just up -d and wondering why nothing changed is the most common update mistake. Second, pull downloads in the background while the old containers keep running, so the actual switchover lasts only the seconds compose needs to stop each old container and start its replacement. This docker compose pull and up -d two-step is the whole trick: the network is the slow part, and you do it while the old version serves.
To update a single service without touching the rest of the stack:
docker compose pull web
docker compose up -d --no-deps web
Add a healthcheck so the new container proves itself
Without a healthcheck, compose treats a container as “started” the moment its process launches, and your reverse proxy may send traffic to an app that is still loading. A docker healthcheck compose block makes compose wait until the app actually answers:
services:
web:
image: myapp:1.4.2
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
interval: 10s
timeout: 5s
retries: 3
start_period: 40s
Pair it with depends_on using condition: service_healthy so workers and schedulers start only after the web app is truly up. The start_period gives slow apps a grace window so the first checks do not kill a container that is still booting.
Rolling updates on a single host
Compose recreates containers one service at a time, which is already brief. For a true rolling update of one service on a single VPS, run two copies behind your reverse proxy, then retire the old one. This works only if the service does not bind a fixed host port; let the reverse proxy route by container instead. Our reverse proxy comparison covers the options that do health-based routing. For zero downtime docker single host deployments, this scale trick is the closest compose gets to a real rolling update:
# 1. fetch the new image while the old container serves traffic
docker compose pull web
# 2. start a second copy with the new image
docker compose up -d --scale web=2 --no-recreate web
# 3. wait until the new copy is healthy
docker compose ps web
# 4. stop and remove the OLD container, then scale back to one
docker compose stop web-old
docker compose rm -f web-old
docker compose up -d --scale web=1 --no-recreate web
An honest caveat: this is a poor man’s rolling update, not Kubernetes. Sessions held in memory drop when the old copy dies, and stateful services should never be scaled this way. For stateless web apps behind a proxy, it keeps the site answering the whole time. Replace web-old with the actual old container name from docker compose ps.
Protect the database before you touch anything
Most update outages are not the app container. They are migrations run against a live database with no way back. Rules that hold up in practice:
- Back up the data volume before every update, not just major ones. Our roundup of backup tools for docker volumes covers restic, kopia, and duplicati setups for exactly this.
- Run migrations separately from the deploy, and keep them backward compatible: add columns before the code that uses them, remove them a release later.
- Never let a container auto-migrate on boot in production unless you can also auto-restore. A failed migration inside an entrypoint script leaves you with a container that will not start and a database halfway changed.
- Know the restore command by heart. A backup you have never restored is a hope, not a plan.
Pin image tags and keep a rollback path
image: myapp:latest means you can never be sure which version is running, and you cannot roll back to a known state. A reliable docker container rollback starts with pinned tags:
image: myapp:1.4.2 # not :latest
Rollback is then one edit and one command away:
# set the compose file back to 1.4.1, then:
docker compose pull web
docker compose up -d --no-deps web
Keep the previous image on disk until the new version has run cleanly for a day. docker image prune is a weekend chore, not a deploy-day chore.
Automate updates without automating disasters
Watchtower and similar tools can update containers for you, but fully automatic updates on a production VPS are how people learn about breaking changes at 3 a.m. A safer middle ground: run Watchtower with --monitor-only so it only notifies you, or schedule a cron job that pulls and recreates at a quiet hour and pages you through Uptime Kuma if the health endpoint goes quiet.
# weekly update, Sundays 03:00, log everything
0 3 * * 0 cd /srv/myapp && /usr/bin/docker compose pull && /usr/bin/docker compose up -d >> /var/log/compose-update.log 2>&1
Post-update checklist
docker compose psshows the new image and a healthy status.- The app logs show a clean start:
docker compose logs --tail=50 web. - The public health endpoint answers 200, and your monitor agrees.
- Disk space is fine; two image versions temporarily double that service’s footprint.
That is the whole routine: pull first, recreate with healthchecks, roll one service at a time when it matters, guard the database, and keep a rollback ready. Run it the same way every time and updates stop being events.