5

I'm running Jenkins from Docker with tag lts. behind this tag was version 2.73.2. Now there is a newer lts version available: 2.73.3. Docker doesn't automatically check for it. I had to do docker pull jenkins/jenkins:lts to get the new version.

But how can check if there is a newer build for a tag?

EDIT: I want to make clear: This is not a duplicate! I asked how to check for a newer Docker image available. I know how to upgrade (as I said above).

Michael
  • 2,528
  • 3
  • 21
  • 54
  • The other question is about upgrade. I know how to upgrade as I wrote in my question. I want to check if an upgrade is needed. – Michael Nov 16 '17 at 11:15
  • Yes, you are right. Looks like it is really not possible in an easy way. – Michael Nov 16 '17 at 13:09

3 Answers3

4

There is a project called Watchtower (https://github.com/v2tec/watchtower), which watches the running container and if there is a new version with the same tag available, it will pull the new image and restart the container.

Jonas Heinisch
  • 363
  • 2
  • 12
0

Docker does not check for newer version of remote image. When building, Docker first check to see if the base image is in the local cache. If it find it is uses it, otherwise it tries to pull it from the remote repository.

I order to get latest image, you have to do it manually by running:

docker pull jenkins/jenkins:lts

Alternatively, you can disable the cache when building and always download the latest image by specifying the --no-cache option:

docker build --no-cache ...
yamenk
  • 46,736
  • 10
  • 93
  • 87
  • I know how to upgrade manually but is there a way to check if an upgrade is needed? – Michael Nov 16 '17 at 11:13
  • @Michael As far as I know, there isn'y an automatic way to check for newer images. Most solutions wrap the build command with a scipt that pulls the image and then builds. – yamenk Nov 16 '17 at 11:19
0

If using docker hub, you can do something like this:

REPOSITORY=XXX
TAG=latest

TOKEN=$(curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$REPOSITORY:pull" | /usr/bin/env python -c 'import sys, json; print(json.load(sys.stdin)["token"])')

TARGET_DIGEST=$(curl -s -H "Authorization: Bearer $TOKEN" -H "Accept: application/vnd.docker.distribution.manifest.v2+json" https://index.docker.io/v2/$REPOSITORY/manifests/$TAG | /usr/bin/env python -c 'import sys, json; print(json.load(sys.stdin)["config"]["digest"])')

if docker images --no-trunc --format "{{.ID}}" $REPOSITORY | grep "$TARGET_DIGEST"; then
    echo "$REPOSITORY:$TAG up to date"
else
    echo "WARNING: $REPOSITORY:$TAG is out of date"
    echo "remote digest $TARGET_DIGEST"
fi
rectalogic
  • 1,266
  • 11
  • 12