Check for Docker image updates
For certain docker-driven services, I would like to check regularly for new versions. One way to do this is to query Docker Hub via Cronjob. Here I provide a little bash script to check for Docker image updates on Docker Hub.
#!/bin/bash # Example usage: # ./docker-image-update-check.sh gitlab/gitlab-ce update-gitlab.sh IMAGE="$1" COMMAND="$2" echo "Fetching Docker Hub token..." token=$(curl --silent "https://auth.docker.io/token?scope=repository:$IMAGE:pull&service=registry.docker.io" | jq -r '.token') echo -n "Fetching remote digest... " digest=$(curl --silent -H "Accept: application/vnd.docker.distribution.manifest.v2+json" \ -H "Authorization: Bearer $token" \ "https://registry.hub.docker.com/v2/$IMAGE/manifests/latest" | jq -r '.config.digest') echo "$digest" echo -n "Fetching local digest... " local_digest=$(docker images -q --no-trunc $IMAGE:latest) echo "$local_digest" if [ "$digest" != "$local_digest" ] ; then echo "Update available. Executing update command..." ($COMMAND) else echo "Already up to date. Nothing to do." fi
The script is also available as a GitHub Gist.
Here is a repository with this and some more scripts: https://gitlab.com/MatthiasLohr/omnibus-gitlab-management-scripts
If you have questions or problems, please create a ticket here.