Created
January 18, 2017 18:43
-
-
Save JamesChevalier/efe4148e819cb205bd862b321e201a9d to your computer and use it in GitHub Desktop.
Update all docker images, ignoring untagged images, and then remove dangling images
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 | |
# 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