Docker - check private registry image version

后端 未结 7 1856
抹茶落季
抹茶落季 2021-01-02 03:37

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.

相关标签:
7条回答
  • 2021-01-02 04:09

    You can use a bash script running in a cron scheduled task:

    #!/bin/bash
    
    docker_instance='YOUR_RUNNING_INSTANCE'
    
    instance_id=$(docker ps -qa --filter name=$docker_instance)
    image_name_tag=$(docker inspect $instance_id | jq -r [] |.Config.Image')
    
    if [ "-${image_name_tag}-" != "--" ]; then
    
        status=$(docker pull $image_name_tag | grep "Downloaded newer image")
        if [ "-${status}-" != "--" ]; then
    
            echo ">>> There is one update for this image ... "
    
            # stop the docker instance
            docker stop $docker_instance
    
            # remove the docker instance
            docker rm $docker_instance
    
            # restart the docker using the last command, using the new image from the remote repository
            run-my-docker-instance.sh
    
        fi
    fi
    
    0 讨论(0)
  • 2021-01-02 04:12

    Not sure about the version but if you mean the tag of image, it can be easily checked through the registry v2 api . Note that in context of docker images tag has nothing to do with the version of software.

    Use curl command in CLI

     curl <docker_host_ip>:<docker_host_port>/v2/<repository_name>/tags/list
    

    To get a list of repositories pushed on the private registry, use

    curl <docker_host_ip>:<docker_host_port>/v2/_catalog
    
    0 讨论(0)
  • 2021-01-02 04:13

    I don't know if this works as advertised. Just a quick hack I just put together. But this will at least give you a little push on how this might be done.

    #!/bin/bash
    
    container=$1
    imageid=$(docker inspect --format '{{.Config.Image}}' ${container})
    
    echo "Running version from: $(docker inspect --format '{{.Created}}' ${container})"
    echo "Image version from: $(docker inspect --format '{{.Created}}' ${imageid})"
    

    Example output:

    [root@server ~]# sh version_check.sh 9e500019b9d4
    Running version from: 2014-05-30T08:24:08.761178656Z
    Image version from: 2014-05-01T16:48:24.163628504Z
    
    0 讨论(0)
  • 2021-01-02 04:15

    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.

    0 讨论(0)
  • 2021-01-02 04:16

    AFAIK, this is not possible right now.

    The only thing I see would be to pull the registry to check if there is a new version of your image (would then have a different ID than your locally stored image):

    docker pull your/image:tag
    

    But yes, that would mean fetching the new images (if any).

    If you have a look at the registry API documentation, you'll see that if you don't mind scripting a bit, you could get this information without actually downloading the image, by fetching the image tags and check if the returned ID for the tag matches the ID of the local image you have with the same tag.

    That being said, having something to "check for updates" integrated into the docker CLI would be a nice addition.

    0 讨论(0)
  • 2021-01-02 04:16

    An older question, but this sounds like a problem that Watchtower can solve for you. It is another dockerized application that runs adjacent to your other containers and periodically check to see if their base images are updated. When they are, it downloads the new image and restarts them.

    If given the correct credentials, it can work with a local registry.

    0 讨论(0)
提交回复
热议问题