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

后端 未结 7 1100
粉色の甜心
粉色の甜心 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条回答
  •  独厮守ぢ
    2021-02-05 00:46

    This is a bit hacky, but it works in most of the cases for me:

    if ! grep -q "my.private.registry.com" ~/.docker/config.json ; then
        docker login "my.private.registry.com"
    fi
    

    Basically, you search if there is a record of "my.private.registry.com" in ~/.docker/config.json. However, if the session is expired, this check won't catch it.

提交回复
热议问题