Skip to content
VDS · Docker and containers

Updating containers without downtime

How to update images so that the service stays up and you can roll back: pinning versions, health checks, the order of steps, and automation.

Updated August 23, 2026

Updating a container is not “pull a new image” but “replace the running version with a new one and be able to roll back.” The difference shows exactly once: when the new version fails to start.

A procedure that works

cd /opt/myapp
docker compose pull
docker compose up -d
docker compose ps
docker compose logs -f --tail 100

Compose recreates only the services whose image changed and leaves the rest alone. Downtime is just the seconds it takes to restart the container.

But before you do this, meet two conditions.

First: versions are pinned. The file must specify postgres:17.2, not postgres:latest. Otherwise pull will one day bring a major version that rewrites the data format, and rollback becomes impossible.

Second: the backup is fresh. An update that breaks the database breaks it irreversibly. Before a major version change, take a dump — see what to back up.

Replacing without a gap

For a web service behind a reverse proxy, downtime drops to almost zero if the container has a health check: the proxy will start sending requests only to a ready instance.

services:
  app:
    image: ghcr.io/example/app:1.5.0
    healthcheck:
      test: ["CMD", "curl", "-fsS", "http://localhost:8080/health"]
      interval: 5s
      timeout: 3s
      retries: 6
      start_period: 20s
docker inspect -f '{{.State.Health.Status}}' <container>

Without a health check, Compose considers the container ready as soon as the process starts — while the application is still reading its settings and applying migrations.

Don't delete the old image until the new version has been running for at least an hour. A rollback means restoring image: ...:1.4.2 and running docker compose up -d, but only as long as the old image is still on disk. docker image prune -a right after an update takes that option away from you.

Rollback

sed -i 's|app:1.5.0|app:1.4.2|' compose.yaml
docker compose up -d app
docker compose logs -f --tail 50 app

If the new version has already changed the database schema, rolling back the image alone isn't enough — you'll need to restore from a backup. That's why major updates are done at a quiet time and with a verified backup: see restore drill.

Automation: be careful

Watchtower can update containers on its own. For home services that's convenient; for production it's a risk: the update arrives at night, breaks the database, and nobody notices. A reasonable compromise is notifications only:

services:
  watchtower:
    image: containrrr/watchtower
    restart: unless-stopped
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    command: --monitor-only --schedule "0 0 6 * * *"

You learn that a new version is out and update manually at a time that suits you.

Rebooting the machine

System packages are updated separately from containers. After a kernel update you need a reboot, and containers with restart: unless-stopped come back up on their own. Test this in advance — with sudo reboot at a quiet time, not during an incident. A soft reboot from the control panel works as long as qemu-guest-agent is installed on the system.

Common mistakes

  • pull without up -d. The new image is downloaded, but the old container is still running.
  • The disk is clogged with old images. Run docker image prune once a month — but not right after an update. See disk space.
  • You updated everything at once. Something breaks — and you can't tell what. Update one service at a time.
  • You didn't read the release notes. An incompatible config file is the most common cause of failure after a major version change; see the breakdown in common Docker problems.