How To Update Docker Container to Latest Version

by Danny
0 comment

READING TIME: 4 MINUTES

In this guide, I’m going to show you how to update one of your docker containers to the latest version in just a few short steps.

For this guide, I’m going to be updating my Homer dashboard to take advantage of the the PING feature, which displays a round circle if the service is reachable by PING. My Homer dashboard was initially created using a Docker-Compose file. If you’re container was created using docker run, you can follow all steps exactly as below except for step 4. More details in that step.

You can follow this tutorial for any running container you have. The process is pretty simple: Check for the image repository name, download(pull) the new image, stop the running container, delete the old container, and then launch a new container with the updated image.

Let’s get started!


Step 1: Check Current Images

First, SSH into your docker host. Then, you need to check what your container image name is.

sudo docker images

It should then show you a full list of pulled images. As you can see, the image I’d like to update is called b4bz/homer.


Step 2: Pull the new image

Then, pull the new image with this command. Replace the repository with whatever container you’d like to update.

By default, it will pull the latest version available. You can pull a specific version if you’d like, but for this example we want the latest.

sudo docker pull b4bz/homer

Step 3: Stop & Remove Old Container

Before you can launch the new container, you first need to stop and remove the old container. If using bind mounts (which you should be doing), you won’t lose any data. It will just remove the old outdate image so you can load the Homer dashboard with the new version.

To stop and remove the old container, first you need to find the name of the running container.

sudo docker ps

Under the CONTAINER ID section, find the container ID of the image you want to update.

It does format the CONTAINER ID section a little weird and makes it a little hard to distinguish which ID goes to which container, so a neat trick I like to use is to highlight the entire row. I know my Homer dashboard runs on port 8092, so I can be sure I’m removing the correct container.

Stop the Running Container

Copy the container ID by using CTRL+SHIFT+C. (Regular CTRL+C to copy won’t work).

Then, type this command (to paste the container ID, use CTRL+SHIFT+V):

sudo docker stop 1d7c55cccdb0

Remove the old container

Then, remove or delete the old container.

sudo docker rm 1d7c55cccdb0

Step 4: Launch the new container

Launch New Container with a Docker-Compose file

Next, we are going to navigate to the directory where your Docker-compose.yml file is located for the container. Mine is located at /srv/config/Homer.

cd /srv/config/Homer

Then, create the new container.

sudo docker-compose up -d

Launch New Container with Docker Run

If you’re container was created using regular Docker run, then the command to launch the new container would look similar to this:

docker run -d \
 -p 8080:8080 \
 -v </your/local/assets/>:/www/assets \
 --restart=always \
 b4bz/homer:latest

Wrapping Up

That’s it! Your image is now updated. If you had a previous version of container running, you may need to restart the container after creating it (not 100% sure if this is necessary). Make sure you are in the correct directory (ie. – /srv/config/Homer), and then run this:

sudo docker-compose restart
0 comment

You may also like

Leave a Comment