Updating a Container with Docker Compose

Updating a Container with Docker Compose

Introduction

Downloading and using docker containers with docker compose is a very easy process and, continuing in that trend, the same can be said for updating your docker container with it.

Prerequisites

It is important to note that during the container update process, unless you specifically have persistent volumes configured in your docker compose file, you are subject to losing any data tied to that container.  It will be as if you had installed the container for the first time.

Persistent volumes are identified simply as volumes: in the docker-compose.yml file, as seen in the example below:

---
version: "2"
services:
  homer:
    image: b4bz/homer
    container_name: homer
    volumes:
      - /home/tcude/docker/homer/data:/www/assets
    ports:
      - 8092:8080
    #environment:
    #  - UID=1000
    #  - GID=1000
    restart: unless-stopped

Updating

With that out of the way, let's get to updating!

To start, simply navigate to the directory of your container's docker compose file and run the command docker-compose pull.  Docker will then provide output, letting you know that it is pulling the latest image of the container, if a new one exists.

Once you have the latest image downloaded, it's simply a matter of running docker-compose up -d. Docker will now recreate the container using the latest image.

This process can be seen here:

If the container was already running the latest image and did not need to update, you will receive the following output.

Conclusion

That's all there is to it! Now you can easily update each of your docker containers with two simple commands.  In the future, I will cover the use of Watchtower, to automate this process.