Update Docker Image and Container to the latest Version
Title: Update Docker Image and Container to the latest Version
Date: 2024-01-10
Time: 09:10
Introduction:
Docker images within a running container do not update automatically. Once you have used an image to create a container, it continues running that version, even after new releases come out.
It is recommended to run containers from the latest Docker image unless you have a specific reason to use an older release.
Step 1: Check Current Version
sudo docker image
Step 2: Pull the Latest Image
# Download the newer version of the image by using DOCKER PULL command
sudo docker pull [docker_image]
# Example
sudo docker pull freshrss:latest
Step 3: Launch a New Updated Container
Once you downloaded the latest Docker image, you need to stop and remove the old container. Then, create a new one with the latest image.
# Find the name of the running container with the outdated image by listing the containers on the system:
sudo docker ps
# Stop and remove the existing container so you can launch a new one under the same name:
sudo docker stop [container_id]
sudo docker rm [container_id]
Misc. Commands: If you have one, make sure to mount the docker volume assigned to the previously used container to ensure the updated container has the same content. To do this, use the -v option followed by the path to the volume directory.
sudo docker run --name=mysql --restart=always -e MYSQL_ROOT_PASSWORD=mypassword -v /path/to/directory:/var/lib/mysql -d mysql
Notes: