Skip to content

Instantly share code, notes, and snippets.

@crayzeigh
Last active March 3, 2021 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crayzeigh/64ae8512174d6049fde590dbf9130710 to your computer and use it in GitHub Desktop.
Save crayzeigh/64ae8512174d6049fde590dbf9130710 to your computer and use it in GitHub Desktop.
Bash Script for automated docker container updates
#!/bin/bash
email="email@domain.com"
# All work done inside body variable to avoid unnecessary writes to disk for raspi
body="Start: $(date)
Checking for new images...
$(/bin/docker-compose -f /path/to/docker-compose.yml pull --no-parallel 2>&1)
Updating changed containers...
$(/bin/docker-compose -f /path/to/docker-compose.yml up -d 2>&1)
End $(date)"
# Only send email if a container was updated/restarted
if [[ ${body} == *"Recreating"* ]]; then
echo "${body}" | mail -s "Docker Updates Completed" ${email}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment