Skip to content

Instantly share code, notes, and snippets.

@vchrisb
Created May 15, 2016 08:16
Show Gist options
  • Select an option

  • Save vchrisb/bd2497b8ff38c10473357e02c6fdb9e9 to your computer and use it in GitHub Desktop.

Select an option

Save vchrisb/bd2497b8ff38c10473357e02c6fdb9e9 to your computer and use it in GitHub Desktop.
#!/bin/bash
echo "Updating images:"
docker images | grep -v '^<none>' | grep -v '^REPOSITORY' | awk '{print $1}' | xargs -L1 docker pull | grep 'Status'
echo -e "\nChecking if a container is not running the latest image:"
CIDS=$(docker ps | grep -v '^CONTAINER ID' | awk '{print $1}')
for CID in $CIDS
do
RUNNING=`docker inspect --type=container --format "{{.Image}}" $CID`
IMAGE=`docker inspect --type=container --format "{{.Config.Image}}" $CID`
LATEST=`docker inspect --type=image --format "{{.Id}}" $IMAGE`
NAME=`docker inspect --format '{{.Name}}' $CID | sed "s/\///g"`
# echo "Latest:" $LATEST
# echo "Running:" $RUNNING
if [ "$RUNNING" != "$LATEST" ];then
echo "$NAME is outdated"
else
echo "$NAME up to date"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment