Quick Update Script for Your Docker Containers

Raspberry Pi – Docker

From time to time, you need to update your docker containers. And when built with docker-compose I have a little update-script for you. Nothing incredibly magical here, just a script that runs through the update commands and restarts the container afterwards.

However, I assume your docker container is defined through a docker-compose.yaml file and built with docker-compose.

#!/usr/bin/env bash

CWD=$(pwd)

# Make sure we are in the current directory with this script
cd $CWD

# Check for docker-compose.yaml file
if [[ -f "docker-compose.yml" || -f "docker-compose.yaml" ]]
    then
        # Updae docker containers
        docker-compose pull

        # Restart docker containers
        docker-compose down
        docker-compose up -d
    else
        echo "'docker-compose.yaml' not found, exiting."
        exit 1
fi

Save this script and make it executable.
To update, run this script in the directory where the containers docker-compose.yaml is located.

Leave a Reply

Your email address will not be published. Required fields are marked *