How to update a Docker container

Updating a docker container that is already running is relatively easy but still very important to make sure you use the latest version of packages. Prior to updating your Docker container it is important to set the correct volumes for your container so that the persistent data of that container application is not removed. Persistent data contains all static and configuration files which you do not want to lose after updating your Docker container.

How to set persistent data location

It is actually very simple to set a persistent data location for static and configuration files that your Docker container uses. As part of the Docker compose configuration you need to set the volume parameter. For Pihole you can see the persistent volume location in the “volumes” section below.

When you are sure the persistent volume data is set, run the following command to update the local docker container for your application (e.g. PiHole in this example).

sudo docker pull pihole/pihole

This will update the local copy of PiHole to the latest available version. You need this to be able to update the container. If you would not update the local copy, the container deployment process would state that the container is already up to date.

Afterwards, update your running docker container via a configuration file that holds all details for your docker application. To run the configuration file run below commands.

sudo docker-compose up -d

The configuration file used (docker-compose.yml) here for Pihole is listed below.

version: "3"

    container_name: pihole
    image: pihole/pihole:latest #for this you need to pull the latest version first
      - "53:53/tcp"
      - "53:53/udp"
      - "67:67/udp"
      - "80:80/tcp"
      - "443:443/tcp"
      TZ: 'Europe/Amsterdam' #this is the time zone
    volumes: #for persistent data location
       - './etc-pihole/:/etc/pihole/'
       - './etc-dnsmasq.d/:/etc/dnsmasq.d/'
      - NET_ADMIN
    restart: unless-stopped