Skip to content

Instantly share code, notes, and snippets.

@composite
Created July 3, 2025 07:35
Show Gist options
  • Save composite/6cd1a09127c1ba799088e8f82d16e44d to your computer and use it in GitHub Desktop.
Save composite/6cd1a09127c1ba799088e8f82d16e44d to your computer and use it in GitHub Desktop.
Docker update and restart (currently not work I'll find why.)
#!/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