To update a docker container or a docker compose stack, you need to pull the new version (image) from Docker Hub or any other container registry and re-create the container using the new image.
Docker is a platform that allows developers to easily create, deploy, and run applications in containers. Containers are a way to package software so that it can run consistently across different environments, like your computer, a server, or even the cloud.
Containers are lightweight, efficient, use less resources than traditional VMs and shares the host system’s kernel and libraries.
To update a docker container or a docker compose stack, you need to pull the new version (image) from Docker Hub or any other container registry and re-create the container using the new image. Container data found in volumes will not be lost during container re-creation. Follow these steps to update any docker container or stack.
Update a single Docker container
Pull the new image using docker pull. You can download specific version by adding its tag to the image name mysql:8.1.0, or don’t specify a version to download latest:
If you want to force Compose to stop and recreate all containers, even if they had no new images available, use the --force-recreate flag:
1
docker compose up -d --force-recreate
From July 2023 Compose V1 stopped receiving updates. It’s also no longer available in new releases of Docker Desktop.
Delete old images to free disk space
List docker images:
1
2
3
4
5
6
7
docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
louislam/uptime-kuma latest fb3a3565b2da 5 days ago 431MB
louislam/uptime-kuma 1 c75c443c4b9a 7 weeks ago 484MB
pihole/pihole latest 566a5a3d4773 2 months ago 301MB
pihole/pihole <none> 4d6ef5c6684a 5 months ago 324MB
Delete one or multiple images using the first few unique letters of the IMAGE ID:
docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
louislam/uptime-kuma latest fb3a3565b2da 5 days ago 431MB
pihole/pihole latest 566a5a3d4773 2 months ago 301MB
Tip: You can cleanup all unused images in your host by using the command docker image prune --all.