Script to update all dockers running on a machine.
This is a script i wrote to manage updates on a number of containers that i run within a directory. The pre-requisite for this script to be used is that you have all your docker-compose.yml files within a directory. They can be within their own folders.
Just sharing so that someone might find it useful.
#!/bin/bash
BASE_DIRECTORY="/data/dockers/"
directories=$(find ${BASE_DIRECTORY} -iname docker-compose.yml -maxdepth 3 | grep -ivw 'excludePattern1\|excludepattern2' | sed 's/docker-compose.yml//g')
echo "(+) Starting to check dockers"
for directory in $directories;do
#echo "(+) Entering directory: $directory"
cd "${directory}"
#echo "(+) Currently in : ${directory}"
docker-compose ps --services --filter "status=running" | grep -i [a-z]
if [ $? -eq 0 ];then
echo "(+) Application ${directory} seems to be running, updating"
docker-compose pull
docker-compose up -d
else
#echo "(-) Application not running, skipping update"
echo ""
fi
cd -
done
echo "(+) Upgrade complete"