Docker - check private registry image version

后端 未结 7 1919
抹茶落季
抹茶落季 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
    

提交回复
热议问题