Ask Steves · Daily notes · VPS, 20% off · AI Profit Lab · SEO · Money Hub

5 November 2026 · One command a day

How do I update a Docker Compose container to the latest image?

This command downloads newer versions of the images your Compose stack uses. It then recreates only the containers whose image has changed. Use it when an app you run in Docker has a new release, or when you want the latest security patches in a base image.

I learn my automation tips in the AI Profit Boardroom. Have a look here. Affiliate link.

The command

cd /opt/appname
sudo docker compose pull && sudo docker compose up -d

Run it from the folder that holds your compose.yaml or docker-compose.yml file. docker compose pull reads that file and fetches the current version of each image tag from its registry. && means the second command only runs if the pull worked, so a failed download leaves your running containers alone. docker compose up -d compares each running container with its image. It stops and recreates the ones that are out of date and leaves the rest running. The -d flag runs everything in the background so you get your prompt back. If your user is in the docker group you can drop sudo.

What you will see

[+] Pulling 2/2
 ✔ db Pulled                        1.8s
 ✔ web Pulled                       6.4s
[+] Running 2/2
 ✔ Container appname-db-1   Running   0.0s
 ✔ Container appname-web-1  Started   2.1s

The first block is the pull. Each service shows as pulled, even if nothing new was downloaded. The second block shows what changed. Running means the container was already up to date and was not touched. Started (often shown as Recreate while it works) means a new image was found and the container was replaced. Check the result with sudo docker compose ps, or watch the new container start up as shown in how to follow a Docker container's logs.

When to use it

Watch out for

The pull can only get you what the tag points to. If your compose file pins an exact version, such as image: postgres:16.4, pulling will never move you to a newer release. You have to edit the tag in the file first, then run the command. Also, services built from a local build: section are not pulled at all. For those, run sudo docker compose up -d --build instead. Before you change a major version of a database image, read its upgrade notes and take a backup. A new major version often cannot read the old data files.

Questions people ask

Will updating the container delete my data?

No, as long as the data lives in a named volume or a mounted folder, because those are kept when the container is recreated. Anything written only inside the container is lost when the container is replaced.

How do I remove the old images afterwards?

Run sudo docker image prune to delete dangling images that no container uses. Old versions pile up after each update, so this saves disk space.

Updating containers on your own schedule is something you can only do on a server you control. For the first run of a stack, see how to start a Docker Compose stack in the background. You can get the same VPS with 20% off at https://asksteves.co.uk/vps. Affiliate link.

Want more automation tips? The AI Profit Boardroom on Skool is where I get mine. Have a look here. Affiliate link.

Everything on this blog runs on one Hostinger KVM 8. This link takes 20% off the same box.

GET A VPS, 20% OFF →

Affiliate link.

Related server notes: How do I free up disk space used by Docker on Linux? · How do I follow a Docker container's logs on Linux? · How do I get a shell inside a running Docker container? · All daily notes