Update All Docker Images In One Line
Update All Docker Images In One Line
The scripts below helps to maintain docker images. It keep images in updated and removes the outdates.
Do In bash/zsh/dash/sh
for img in $(docker images | sed '1d' | awk '{print $1":"$2}' | sort)
do
echo "#### Updating docker image $img ####"
docker pull "$img"
echo
done
for img in $(docker images | grep '<none>' | awk '{print $3}')
do
echo "#### Removing outdated docker image $img ####"
docker rmi "$img"
echo
done
Do In fish
for img in (docker images | sed '1d' | awk '{print $1":"$2}' | sort)
echo "#### Updating docker image $img ####"
docker pull "$img"
echo
end
for img in (docker images | grep '<none>' | awk '{print $3}')
echo "#### Removing outdated docker image $img ####"
docker rmi "$img"
echo
end
Automatic In cron
# Update docker images & remove outdated docker images
@daily for i in $(docker images | sed '1d' | awk '{print $1":"$2}' | sort); do docker pull "$i"; done; for i in $(docker images | grep '<none>' | awk '{print $3}'); do docker rmi "$i"; done