Skip to content

Instantly share code, notes, and snippets.

@JamesChevalier
Created January 18, 2017 18:43
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 JamesChevalier/efe4148e819cb205bd862b321e201a9d to your computer and use it in GitHub Desktop.
Save JamesChevalier/efe4148e819cb205bd862b321e201a9d to your computer and use it in GitHub Desktop.
Update all docker images, ignoring untagged images, and then remove dangling images
#!/bin/bash
# collect the list of docker images
images=$(docker images --format "{{.Repository}}:{{.Tag}}")
# iterate through each image
for image in $images
do
if [[ $image != *"<none>"* ]]; then
# the image is tagged, so pull the latest version
echo "Pulling $image"
docker pull $image
else
# the image isn't tagged (it's dangling), so skip it
echo "Skipping $image"
fi
# output a visual indicator between each image processing
echo =========================================================================
done
# removing dangling (untagged) images
docker rmi $(docker images --format "{{.ID}}" --filter "dangling=true")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment