How can I tell if I'm logged in to a private Docker registry from a script?

后端 未结 7 1119
粉色の甜心
粉色の甜心 2021-02-04 23:59

How can I tell whether or not I\'m logged in to a private Docker registry server from a script? In other words, has docker login some.registry.com been run success

7条回答
  •  旧时难觅i
    2021-02-05 00:45

    When you do the

    Docker login  -u  -p  
    

    command from your terminal, you will have a response: (stored in $?)

    0
    Login Succeeded
    

    if you were successful.

    In your shell script, you could just look at the response you're receiving, if it does not equal 0, you've failed to login.

    sudo docker login  -u  -p 
    if [ $? -ne 0 ]; then
        echo Login failed!
    else
        echo Login OK!
    fi
    

提交回复
热议问题