Skip to content

Instantly share code, notes, and snippets.

@mbierman
Last active December 24, 2024 22:49
Show Gist options
  • Save mbierman/6cf22430ca0c2ddb699ac8780ef281ef to your computer and use it in GitHub Desktop.
Save mbierman/6cf22430ca0c2ddb699ac8780ef281ef to your computer and use it in GitHub Desktop.
Update Docker containers on Fireawlla
#!/bin/bash
# version 3.2.0
# https://gist.github.com/mbierman/6cf22430ca0c2ddb699ac8780ef281ef
wait=1
container=$1
DOCKER=$(which docker)
# Check if Docker is installed
if [ -z "$DOCKER" ]; then
echo "Error: Docker is not installed or not in your PATH."
exit 1
fi
function finished () {
echo -e "\n please wait ($wait seconds) for the container to restart"
while [ "$ready" != "Up" ] ; do
sleep $wait
ready=$(sudo docker ps | grep $container | grep -o 'Up')
done
echo "$image refreshed"
# sudo $DOCKER container prune -f
}
if [ "$container" = "homebridge" ]; then
image="homebridge/homebridge:ubuntu"
elif [ "$container" = "docker-notify" ]; then
image="schlabbi/docker-notify:latest"
elif [ "$container" = "unifi" ]; then
image="jacobalberty/unifi:latest"
elif [ "$container" = "ddns" ]; then
image="oznu/cloudflare-ddns:latest"
else
echo -e "Container not supported\nUse \"homebridge\", \"docker-notify\", \"unifi\" "
exit
fi
echo "Checking container..."
versioncheck=$( sudo $DOCKER pull $image| tee /dev/tty | grep -c "Status: Image is up to date" )
if [ $versioncheck = 1 ] ; then
echo "No update required."
exit
else
read -n 1 -s -r -p "Want to update $image ? \n\nPress any key to continue."
yaml=/home/pi/.firewalla/run/docker/$container
cd $yaml
echo "stopping $image..."
sudo $DOCKER container stop $container && echo "removing ${container}'s container" && sudo $DOCKER container rm $container
sudo $DOCKER image prune -f
sudo $DOCKER system prune -f
echo "bringing $image up"
sudo docker-compose up -d
sudo $DOCKER ps
read -n 1 -s -r -p "Ready to clean up. Press any key to continue."
finished
fi
@mbierman
Copy link
Author

mbierman commented Dec 14, 2021

I use this to update various docker containers on several platforms so I don't have to remember how and I don't make any mistakes. To install, ssh to your Firewalla

% cd ~/.firewalla/run/docker
% curl -o dockerupdate.sh https://gist.githubusercontent.com/mbierman/6cf22430ca0c2ddb699ac8780ef281ef/raw/57f0de8bd42a4dad39f1ed7fc5f746d53cedc7ed/updatedocker.sh
% chmod +x dockerupdate.sh

Then to update,

~/.firewalla/run/docker/dockerupdate.sh [docker_image_name]

Tested docker images:

  • unifi
  • homebridge

You will need to adjust this script a bit to use it on something other than a firewalla.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment