One minute
Hands Off Updating Docker Containers
In this article I want to paste a code snippet which is checking it’s filtered subfolders for docker-compose files and pulls and ups automagically.
Here it is!
#!/bin/bash
# our docker base folder
DOCKER_BASE_DIR="/home/user/docker"
# folders to exclude from udpate
DIRS_TO_EXCLUDE=("code" "snacklish" "nginx-proxy" "psono")
# docker-compose binary location
DC=$(which docker-compose)
cd ${DOCKER_BASE_DIR}
for D in *; do
# if is directory and not excluded
if ([ -d "${D}" ] && [[ ! " ${DIRS_TO_EXCLUDE[@]} " =~ " ${D} " ]]); then
cd ${D}
echo "I am in $(pwd)"
if [ -f "./docker-compose.yaml" ]; then
echo "I found a docker-compose.yaml, updating ..."
${DC} pull && ${DC} up -d && cd ..
else
echo "No docker-compose.yaml found, stepping back"
cd ..
fi
fi
done
Oriented on Selenium acceptance tests, I have designed the output to be as readable and as debuggable as possible.
user@host ~/docker % ./update-all.sh
I am in /home/user/docker/gitlab
I found a docker-compose.yaml, updating ...
Pulling gitlab ... done
Recreating gitlab ... done
I am in /home/user/docker/mailcow
No docker-compose.yaml found, stepping back
I am in /home/user/docker/traefik
I found a docker-compose.yaml, updating ...
Pulling traefik ... done
traefik_traefik_1 is up-to-date
README