Docker - check private registry image version

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

    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
    

提交回复
热议问题