Last active
June 24, 2024 01:39
-
-
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 | |
DOCKER=$(which docker) | |
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 $1 | grep -o 'Up') | |
done | |
} | |
wait=1 | |
image=$1 | |
if [ "$1" = "homebridge" ]; then | |
container="homebridge/homebridge:ubuntu" | |
elif [ "$1" = "docker-notify" ]; then | |
container="schlabbi/docker-notify:latest" | |
elif [ "$1" = "unifi" ]; then | |
container="jacobalberty/unifi:latest" | |
elif [ "$1" = "ddns" ]; then | |
container="oznu/cloudflare-ddns:latest" | |
else | |
echo -e "Container not supported\nUse \"homebridge\", \"docker-notify\", \"unifi\" " | |
exit | |
fi | |
myvar=$( sudo $DOCKER pull $container | tee /dev/tty | grep -c "Status: Image is up to date" ) | |
echo "Checking container..." | |
myvar=$( sudo $DOCKER pull $container | tee /dev/tty | grep -c "Status: Image is up to date" ) | |
if [ $myvar = 1 ] ; then | |
echo "No update required." | |
exit | |
else | |
read -n 1 -s -r -p "Want to update $container? \n\nPress any key to continue." | |
echo "Pulling Container" | |
echo "stopping $1's..." | |
cd /home/pi/.firewalla/run/docker/$1 | |
sudo $DOCKER container stop $1 && echo "removing $1's container" && sudo $DOCKER container rm $1 | |
sudo docker-compose up -d | |
sudo $DOCKER ps | |
finished $1 | |
read -n 1 -s -r -p "Ready to clean up. Press any key to continue." | |
sudo $DOCKER image prune -f | |
sudo $DOCKER container prune -f | |
sudo $DOCKER system prune -f | |
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.