How to know if docker is already logged in to a docker registry server

后端 未结 13 2478
后悔当初
后悔当初 2020-12-23 02:49

I\'m not sure if I have already logged in to a docker registry in cmd line by using cmd: docker login. How can you test or see whether you are logged in or not, without tryi

13条回答
  •  情话喂你
    2020-12-23 03:19

    The answers here so far are not so useful:

    • docker info no longer provides this info
    • docker logout is a major inconvenience - unless you already know the credentials and can easily re-login
    • docker login response seems quite unreliable and not so easy to parse by the program

    My solution that worked for me builds on @noobuntu's comment: I figured that if I already known the image that I want to pull, but I'm not sure if the user is already logged in, I can do this:

    try pulling target image
    -> on failure:
       try logging in
       -> on failure: throw CannotLogInException
       -> on success:
          try pulling target image
          -> on failure: throw CannotPullImageException
          -> on success: (continue)
    -> on success: (continue)
    

提交回复
热议问题