Skip to content

Instantly share code, notes, and snippets.

@biggianteye
Created March 13, 2018 17:27
Show Gist options
  • Save biggianteye/39e83d7ca1d14de35eee6d37fd8f795d to your computer and use it in GitHub Desktop.
Save biggianteye/39e83d7ca1d14de35eee6d37fd8f795d to your computer and use it in GitHub Desktop.
Pull down the latest version of docker images
#!/bin/sh
# Pull down the latest docker images
#
# "docker-compose pull" will pull down the latest images but will not do it
# intelligently as it will attempt to update things multiple times if they
# are dependencies of several services (eg. mysql).
#
# It will also only work on the current directory.
#
# This script will:
# - Only attempt to update an image *once*.
# - Process all the docker-compose.yml files in the given directory and
# all subdirectories.
if [ "$#" -ne 1 ] || ! [ -d "$1" ]; then
echo "Usage: $0 [directory]" >&2
exit 1
fi
cd $1
# Find all non-vendor docker-compose.yml files.
files=$(find . -name docker-compose.yml | egrep -v 'vendor|node_modules')
# Pull out the images used
# Have to filter out "image: {ecr}/{repo}:{tag}"
images=$(grep -h image: $files | grep -v '{' | awk '{ print $2 }' | sort | uniq)
# Now do the update
for image in $images
do
docker pull $image
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment