Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker - check private registry image version

What CLI commands do I need to use in order to check if the image in my private docker registry is a newer version than the one currently running on my server?

E.g. I have a container that I ran using docker run -d my.domain.com:5000/project1

and I would like to know if it is out-of-date.

like image 850
Programster Avatar asked Jun 25 '14 13:06

Programster


2 Answers

Brownie points to @mbarthelemy and @amuino who put me on track. From that I was able to come up with the following bash script that others may find useful. It just checks if the tag on the registry is different from the currently executing container.

#!/bin/bash
# ensure running bash
if ! [ -n "$BASH_VERSION" ];then
    echo "this is not bash, calling self with bash....";
    SCRIPT=$(readlink -f "$0")
    /bin/bash $SCRIPT
    exit;
fi


REGISTRY="my.registry.com:5000"
REPOSITORY="awesome-project-of-awesomeness"


LATEST="`wget -qO- http://$REGISTRY/v1/repositories/$REPOSITORY/tags`"
LATEST=`echo $LATEST | sed "s/{//g" | sed "s/}//g" | sed "s/\"//g" | cut -d ' ' -f2`

RUNNING=`docker inspect "$REGISTRY/$REPOSITORY" | grep Id | sed "s/\"//g" | sed "s/,//g" |  tr -s ' ' | cut -d ' ' -f3`

if [ "$RUNNING" == "$LATEST" ];then
    echo "same, do nothing"
else
    echo "update!"
    echo "$RUNNING != $LATEST"
fi
like image 115
Programster Avatar answered Sep 21 '22 18:09

Programster


Even when there is no command, you can use the API to check for tags on the registry and compare against what you are running.

$ curl --silent my.domain.com:5000/v1/repositories//project1/tags | grep latest
{"latest": "116f283e4f19716a07bbf48a562588d58ec107fe6e9af979a5b1ceac299c4370"}

$ docker images --no-trunc my.domain.com:5000/project1
REPOSITORY           TAG                 IMAGE ID                                                           CREATED             VIRTUAL SIZE
my.domain.com:5000   latest              64d935ffade6ed1cca3de1b484549d4d278a5ca62b31165e36e72c3e6ab8a30f   4 days ago          583.2 MB

By comparing the ids, you can know that you are not running the latest version.

like image 33
Abel Muiño Avatar answered Sep 20 '22 18:09

Abel Muiño