Created
July 3, 2025 07:35
-
-
Save composite/6cd1a09127c1ba799088e8f82d16e44d to your computer and use it in GitHub Desktop.
Docker update and restart (currently not work I'll find why.)
This file contains hidden or 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 | |
#set -ex | |
day=$(date '+%Y%m%d') | |
now=$(date '+%Y-%m-%d %H:%M:%S') | |
dir=$(dirname "$0") | |
out=$(sudo docker compose --project-directory "$dir" -f "$dir/docker-compose.yml" pull) | |
log="$dir/log/pull-$day.log" | |
mkdir -p $(dirname "$log") | |
if [[ $out == *"Pulled"* ]]; then | |
echo "application-dev - $now : Updated image detected. restarting with new image..." | tee -a "$log" | |
pushd . | |
cd "$dir" | |
sudo docker compose down | |
sudo docker compose up -d | |
sudo docker image prune -f | |
popd | |
echo "application-dev - $now : Done." | tee -a "$log" | |
else | |
echo "application-dev - $now : Up to date." | tee -a "$log" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment