Update Docker Compose Images
Keeping your containers up-to-date is essential for security and features. Here is how to update images in a Docker Compose stack.
The Standard Update Flow
To update your running services, follow these three steps:
1. Pull the latest images
docker compose pull
This downloads the latest version of the images specified in your docker-compose.yml.
Note: This only works if you use mutable tags like
latestorv1(which points tov1.2,v1.3etc). If you pin a specific version likepostgres:15.2, pulling won't do anything until you edit the YAML file topostgres:15.3.
2. Recreate the containers
docker compose up -d
Docker Compose is smart. It checks if the image ID has changed. If it has, it stops the old container, recreates it with the new image, and starts it. If the image hasn't changed, it does nothing.
3. Remove old images (Optional)
After updating, you might have "dangling" images (the old versions) taking up space.
docker image prune -f
One-Liner Update
You can combine these into a single command alias:
docker compose pull && docker compose up -d && docker image prune -f
Updating a Specific Service
If you only want to update the web service:
docker compose pull web
docker compose up -d web
Zero-Downtime Updates?
Docker Compose natively restarts containers one by one, but there will be a brief downtime (seconds) while the new process starts.
For true zero-downtime deployments (rolling updates), you typically need:
- Multiple replicas of the service.
- A load balancer (like Nginx or Traefik) in front.
docker compose up -d --scale web=2 --no-recreatestrategies (complex to manage manually).
Better Solution: Use a platform that handles rolling updates for you.
Automated Updates on Hostim
Hostim.dev can automatically pull and redeploy your containers when you push to your Git branch or Docker registry. Zero hassle.