Skip to main content
  1. Posts/

TIL how to update docker compose images the right way

·233 words·2 mins
Photo by Venti Views on Unsplash

Every time I want to update my docker images, I’m a bit confused about the best way to do it. I run all my images using docker compose. Sometimes I want to update a single image to try a new feature, and sometimes I update all of them at once.

The reason for this post is that the last time when I tried to update all my images, it did not go as planned. I updated all images by removing the running images, and then restarting them.

When you remove an image and then restart your container, docker will always pull the latest image version. While this usually works, it gave me issues this time because I run adguard as my DNS server. Removing adguard meant that the image got taken down before the new image was available. No DNS means no internet1. No internet means no new docker images to pull. Not ideal. 😅

I find it works better to first pull the new image(s) and then restarting the containers:

1
2
3
docker compose pull
docker compose down
docker compose up -d

To pull the image for a specific service:

1
docker compose pull adguard

or by its image name directly:

1
docker pull adguard/adguardhome

Optionally, remove old unused images:

1
docker image prune

  1. Well, mostly. At least firefox caches DNS requests, so my frequently visited sites are still accessible somehow. ↩︎