Last active
December 24, 2024 22:49
-
-
Save mbierman/6cf22430ca0c2ddb699ac8780ef281ef to your computer and use it in GitHub Desktop.
Update Docker containers on Fireawlla
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Then to update,
Tested docker images:
You will need to adjust this script a bit to use it on something other than a firewalla.