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











up vote
50
down vote

favorite
5












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 trying to push?










share|improve this question






















  • Not sure I understand your question? do you want to know if you are logged in on a terminal? why not run %docker images command in the terminal and see if your images show up?
    – noobuntu
    Mar 15 '16 at 21:54








  • 1




    I want to know whether I am logged in to dockerhub registry in terminal. I thought the images are local, so it will just show the local images, not the dockerhub images.
    – Ville Miekk-oja
    Mar 15 '16 at 21:56








  • 1




    I believe once you are logged into docker, you are connected to your dockerhub registry. I don't think there is a separate login
    – noobuntu
    Mar 15 '16 at 22:01















up vote
50
down vote

favorite
5












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 trying to push?










share|improve this question






















  • Not sure I understand your question? do you want to know if you are logged in on a terminal? why not run %docker images command in the terminal and see if your images show up?
    – noobuntu
    Mar 15 '16 at 21:54








  • 1




    I want to know whether I am logged in to dockerhub registry in terminal. I thought the images are local, so it will just show the local images, not the dockerhub images.
    – Ville Miekk-oja
    Mar 15 '16 at 21:56








  • 1




    I believe once you are logged into docker, you are connected to your dockerhub registry. I don't think there is a separate login
    – noobuntu
    Mar 15 '16 at 22:01













up vote
50
down vote

favorite
5









up vote
50
down vote

favorite
5






5





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 trying to push?










share|improve this question













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 trying to push?







docker






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 15 '16 at 21:50









Ville Miekk-oja

2,78992958




2,78992958












  • Not sure I understand your question? do you want to know if you are logged in on a terminal? why not run %docker images command in the terminal and see if your images show up?
    – noobuntu
    Mar 15 '16 at 21:54








  • 1




    I want to know whether I am logged in to dockerhub registry in terminal. I thought the images are local, so it will just show the local images, not the dockerhub images.
    – Ville Miekk-oja
    Mar 15 '16 at 21:56








  • 1




    I believe once you are logged into docker, you are connected to your dockerhub registry. I don't think there is a separate login
    – noobuntu
    Mar 15 '16 at 22:01


















  • Not sure I understand your question? do you want to know if you are logged in on a terminal? why not run %docker images command in the terminal and see if your images show up?
    – noobuntu
    Mar 15 '16 at 21:54








  • 1




    I want to know whether I am logged in to dockerhub registry in terminal. I thought the images are local, so it will just show the local images, not the dockerhub images.
    – Ville Miekk-oja
    Mar 15 '16 at 21:56








  • 1




    I believe once you are logged into docker, you are connected to your dockerhub registry. I don't think there is a separate login
    – noobuntu
    Mar 15 '16 at 22:01
















Not sure I understand your question? do you want to know if you are logged in on a terminal? why not run %docker images command in the terminal and see if your images show up?
– noobuntu
Mar 15 '16 at 21:54






Not sure I understand your question? do you want to know if you are logged in on a terminal? why not run %docker images command in the terminal and see if your images show up?
– noobuntu
Mar 15 '16 at 21:54






1




1




I want to know whether I am logged in to dockerhub registry in terminal. I thought the images are local, so it will just show the local images, not the dockerhub images.
– Ville Miekk-oja
Mar 15 '16 at 21:56






I want to know whether I am logged in to dockerhub registry in terminal. I thought the images are local, so it will just show the local images, not the dockerhub images.
– Ville Miekk-oja
Mar 15 '16 at 21:56






1




1




I believe once you are logged into docker, you are connected to your dockerhub registry. I don't think there is a separate login
– noobuntu
Mar 15 '16 at 22:01




I believe once you are logged into docker, you are connected to your dockerhub registry. I don't think there is a separate login
– noobuntu
Mar 15 '16 at 22:01












8 Answers
8






active

oldest

votes

















up vote
30
down vote



accepted










Edit



You can login to docker with docker login <repository>



$ docker login
Login with your Docker ID to push and pull images from Docker Hub. If
you don't have a Docker ID, head over to https://hub.docker.com to
create one.
Username:


If you are already logged in, the prompt will look like:



$ docker login
Login with your Docker ID to push and pull images from Docker Hub. If
you don't have a Docker ID, head over to https://hub.docker.com to
create one.
Username (myusername):


Answer below is obsolete, docker info no longer shows username information.



Historic



When you are logged in, your username and registry shows up in the docker info command



Like this:



[ciccio@consolecowboy.net ~]$ docker info
Containers: 12
Running: 2
..etc...
...
Username: francobolli
Registry: https://index.docker.io/v1/


Edit: Note; this only works for index.docker.io repo. Login only stores the credentials on disk when it needs them, for example when running docker pull localhost:5000/image or docker pull quay.io/username/reponame.



Edited after this got pointed out in the comments of this question: how can I tell if I'm logged into a private docker registry






share|improve this answer



















  • 1




    The last link talks about checking the contents of ~/.docker/config.json.
    – dusan
    Nov 27 '17 at 15:39






  • 2




    docker info is apparently unreliable even for index.docker.io. Currently logged in alright and only see the Registry entry, no Username.
    – famousgarkin
    Apr 25 at 6:15










  • docker info is not showing Username anymore. I am on Windows, with docker version 18.05.0-ce.
    – Giovanni Bassi
    Jun 22 at 1:24










  • @GiovanniBassi I have updated my answer, thank you.
    – Francesco de Guytenaere
    Jun 24 at 17:05






  • 1




    What if a script needs to check?
    – Teekin
    Jul 7 at 11:03


















up vote
24
down vote













I use one of the following two ways for this check:



1: View config.json file:



In case you are logged in to "private.registry.com" you will see an entry for the same as following in ~/.docker/config.json:



"auths": {
"private.registry.com": {
"auth": "gibberishgibberishgibberishgibberishgibberishgibberish"
}
}


2: Try docker login once again:



If you are trying to see if you already have an active session with private.registry.com, try to login again:



bash$ docker login private.registry.com
Username (logged-in-user):


If you get an output like the above, it means logged-in-user already had an active session with private.registry.com. If you are just promoted for username instead, that would indicate that there's no active session.






share|improve this answer























  • Thanks a lot, this is the best answer
    – Shqear
    Mar 21 at 22:09










  • Yes, this is the best answer, because it provides a way to determine this in a shell script or other program.
    – Teekin
    Jul 7 at 11:05


















up vote
4
down vote













For private registries, nothing is shown in docker info. However, the logout command will tell you if you were logged in:



 $ docker logout private.example.com
Not logged in to private.example.com


(Though this will force you to log in again.)






share|improve this answer




























    up vote
    2
    down vote













    At least in "Docker for Windows" you can see if you are logged in to docker hub over the UI. Just right click the docker icon in the windows notification area:
    Docker Logged in






    share|improve this answer




























      up vote
      2
      down vote













      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)





      share|improve this answer





















      • This is by far the best stratgy: just try a pull, if it fails then it is not logged in (the rest of the logic you have will depend on each use case, but the first try is universally applicable).
        – Oliver
        Nov 11 at 6:00










      • However someone pointed out on github.com/moby/moby/issues/15466 that there are many reasons for failure, not just login issue, yet docker exit status does not allow to differentiate reason for failure. It's still better than the other solutions, but a full solution would require a patch to docker.
        – Oliver
        Nov 11 at 6:08


















      up vote
      1
      down vote













      Use command like below:



      docker info | grep 'name'

      WARNING: No swap limit support
      Username: <strong>jonasm2009</strong>





      share|improve this answer






























        up vote
        0
        down vote













        Just checked, today it looks like this:



        $ docker login
        Authenticating with existing credentials...
        Login Succeeded


        NOTE: this is on a macOS with the latest version of Docker CE, docker-credential-helper - both installed with homebrew.






        share|improve this answer




























          up vote
          0
          down vote













          As pointed out by @Christian, best to try operation first then login only if necessary. Problem is that "if necessary" is not that obvious to do robustly. One approach is to compare the stderr of the docker operation with some strings that are known (by trial and error). For example,



          try "docker OPERATION"
          if it failed:
          capture the stderr of "docker OPERATION"
          if it ends with "no basic auth credentials":
          try docker login
          else if it ends with "not found":
          fatal error: image name/tag probably incorrect
          else if it ends with <other stuff you care to trap>:
          ...
          else:
          fatal error: unknown cause

          try docker OPERATION again
          if this fails: you're SOL!





          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f36022892%2fhow-to-know-if-docker-is-already-logged-in-to-a-docker-registry-server%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            8 Answers
            8






            active

            oldest

            votes








            8 Answers
            8






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            30
            down vote



            accepted










            Edit



            You can login to docker with docker login <repository>



            $ docker login
            Login with your Docker ID to push and pull images from Docker Hub. If
            you don't have a Docker ID, head over to https://hub.docker.com to
            create one.
            Username:


            If you are already logged in, the prompt will look like:



            $ docker login
            Login with your Docker ID to push and pull images from Docker Hub. If
            you don't have a Docker ID, head over to https://hub.docker.com to
            create one.
            Username (myusername):


            Answer below is obsolete, docker info no longer shows username information.



            Historic



            When you are logged in, your username and registry shows up in the docker info command



            Like this:



            [ciccio@consolecowboy.net ~]$ docker info
            Containers: 12
            Running: 2
            ..etc...
            ...
            Username: francobolli
            Registry: https://index.docker.io/v1/


            Edit: Note; this only works for index.docker.io repo. Login only stores the credentials on disk when it needs them, for example when running docker pull localhost:5000/image or docker pull quay.io/username/reponame.



            Edited after this got pointed out in the comments of this question: how can I tell if I'm logged into a private docker registry






            share|improve this answer



















            • 1




              The last link talks about checking the contents of ~/.docker/config.json.
              – dusan
              Nov 27 '17 at 15:39






            • 2




              docker info is apparently unreliable even for index.docker.io. Currently logged in alright and only see the Registry entry, no Username.
              – famousgarkin
              Apr 25 at 6:15










            • docker info is not showing Username anymore. I am on Windows, with docker version 18.05.0-ce.
              – Giovanni Bassi
              Jun 22 at 1:24










            • @GiovanniBassi I have updated my answer, thank you.
              – Francesco de Guytenaere
              Jun 24 at 17:05






            • 1




              What if a script needs to check?
              – Teekin
              Jul 7 at 11:03















            up vote
            30
            down vote



            accepted










            Edit



            You can login to docker with docker login <repository>



            $ docker login
            Login with your Docker ID to push and pull images from Docker Hub. If
            you don't have a Docker ID, head over to https://hub.docker.com to
            create one.
            Username:


            If you are already logged in, the prompt will look like:



            $ docker login
            Login with your Docker ID to push and pull images from Docker Hub. If
            you don't have a Docker ID, head over to https://hub.docker.com to
            create one.
            Username (myusername):


            Answer below is obsolete, docker info no longer shows username information.



            Historic



            When you are logged in, your username and registry shows up in the docker info command



            Like this:



            [ciccio@consolecowboy.net ~]$ docker info
            Containers: 12
            Running: 2
            ..etc...
            ...
            Username: francobolli
            Registry: https://index.docker.io/v1/


            Edit: Note; this only works for index.docker.io repo. Login only stores the credentials on disk when it needs them, for example when running docker pull localhost:5000/image or docker pull quay.io/username/reponame.



            Edited after this got pointed out in the comments of this question: how can I tell if I'm logged into a private docker registry






            share|improve this answer



















            • 1




              The last link talks about checking the contents of ~/.docker/config.json.
              – dusan
              Nov 27 '17 at 15:39






            • 2




              docker info is apparently unreliable even for index.docker.io. Currently logged in alright and only see the Registry entry, no Username.
              – famousgarkin
              Apr 25 at 6:15










            • docker info is not showing Username anymore. I am on Windows, with docker version 18.05.0-ce.
              – Giovanni Bassi
              Jun 22 at 1:24










            • @GiovanniBassi I have updated my answer, thank you.
              – Francesco de Guytenaere
              Jun 24 at 17:05






            • 1




              What if a script needs to check?
              – Teekin
              Jul 7 at 11:03













            up vote
            30
            down vote



            accepted







            up vote
            30
            down vote



            accepted






            Edit



            You can login to docker with docker login <repository>



            $ docker login
            Login with your Docker ID to push and pull images from Docker Hub. If
            you don't have a Docker ID, head over to https://hub.docker.com to
            create one.
            Username:


            If you are already logged in, the prompt will look like:



            $ docker login
            Login with your Docker ID to push and pull images from Docker Hub. If
            you don't have a Docker ID, head over to https://hub.docker.com to
            create one.
            Username (myusername):


            Answer below is obsolete, docker info no longer shows username information.



            Historic



            When you are logged in, your username and registry shows up in the docker info command



            Like this:



            [ciccio@consolecowboy.net ~]$ docker info
            Containers: 12
            Running: 2
            ..etc...
            ...
            Username: francobolli
            Registry: https://index.docker.io/v1/


            Edit: Note; this only works for index.docker.io repo. Login only stores the credentials on disk when it needs them, for example when running docker pull localhost:5000/image or docker pull quay.io/username/reponame.



            Edited after this got pointed out in the comments of this question: how can I tell if I'm logged into a private docker registry






            share|improve this answer














            Edit



            You can login to docker with docker login <repository>



            $ docker login
            Login with your Docker ID to push and pull images from Docker Hub. If
            you don't have a Docker ID, head over to https://hub.docker.com to
            create one.
            Username:


            If you are already logged in, the prompt will look like:



            $ docker login
            Login with your Docker ID to push and pull images from Docker Hub. If
            you don't have a Docker ID, head over to https://hub.docker.com to
            create one.
            Username (myusername):


            Answer below is obsolete, docker info no longer shows username information.



            Historic



            When you are logged in, your username and registry shows up in the docker info command



            Like this:



            [ciccio@consolecowboy.net ~]$ docker info
            Containers: 12
            Running: 2
            ..etc...
            ...
            Username: francobolli
            Registry: https://index.docker.io/v1/


            Edit: Note; this only works for index.docker.io repo. Login only stores the credentials on disk when it needs them, for example when running docker pull localhost:5000/image or docker pull quay.io/username/reponame.



            Edited after this got pointed out in the comments of this question: how can I tell if I'm logged into a private docker registry







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jun 24 at 17:04

























            answered Mar 15 '16 at 23:07









            Francesco de Guytenaere

            2,26711631




            2,26711631








            • 1




              The last link talks about checking the contents of ~/.docker/config.json.
              – dusan
              Nov 27 '17 at 15:39






            • 2




              docker info is apparently unreliable even for index.docker.io. Currently logged in alright and only see the Registry entry, no Username.
              – famousgarkin
              Apr 25 at 6:15










            • docker info is not showing Username anymore. I am on Windows, with docker version 18.05.0-ce.
              – Giovanni Bassi
              Jun 22 at 1:24










            • @GiovanniBassi I have updated my answer, thank you.
              – Francesco de Guytenaere
              Jun 24 at 17:05






            • 1




              What if a script needs to check?
              – Teekin
              Jul 7 at 11:03














            • 1




              The last link talks about checking the contents of ~/.docker/config.json.
              – dusan
              Nov 27 '17 at 15:39






            • 2




              docker info is apparently unreliable even for index.docker.io. Currently logged in alright and only see the Registry entry, no Username.
              – famousgarkin
              Apr 25 at 6:15










            • docker info is not showing Username anymore. I am on Windows, with docker version 18.05.0-ce.
              – Giovanni Bassi
              Jun 22 at 1:24










            • @GiovanniBassi I have updated my answer, thank you.
              – Francesco de Guytenaere
              Jun 24 at 17:05






            • 1




              What if a script needs to check?
              – Teekin
              Jul 7 at 11:03








            1




            1




            The last link talks about checking the contents of ~/.docker/config.json.
            – dusan
            Nov 27 '17 at 15:39




            The last link talks about checking the contents of ~/.docker/config.json.
            – dusan
            Nov 27 '17 at 15:39




            2




            2




            docker info is apparently unreliable even for index.docker.io. Currently logged in alright and only see the Registry entry, no Username.
            – famousgarkin
            Apr 25 at 6:15




            docker info is apparently unreliable even for index.docker.io. Currently logged in alright and only see the Registry entry, no Username.
            – famousgarkin
            Apr 25 at 6:15












            docker info is not showing Username anymore. I am on Windows, with docker version 18.05.0-ce.
            – Giovanni Bassi
            Jun 22 at 1:24




            docker info is not showing Username anymore. I am on Windows, with docker version 18.05.0-ce.
            – Giovanni Bassi
            Jun 22 at 1:24












            @GiovanniBassi I have updated my answer, thank you.
            – Francesco de Guytenaere
            Jun 24 at 17:05




            @GiovanniBassi I have updated my answer, thank you.
            – Francesco de Guytenaere
            Jun 24 at 17:05




            1




            1




            What if a script needs to check?
            – Teekin
            Jul 7 at 11:03




            What if a script needs to check?
            – Teekin
            Jul 7 at 11:03












            up vote
            24
            down vote













            I use one of the following two ways for this check:



            1: View config.json file:



            In case you are logged in to "private.registry.com" you will see an entry for the same as following in ~/.docker/config.json:



            "auths": {
            "private.registry.com": {
            "auth": "gibberishgibberishgibberishgibberishgibberishgibberish"
            }
            }


            2: Try docker login once again:



            If you are trying to see if you already have an active session with private.registry.com, try to login again:



            bash$ docker login private.registry.com
            Username (logged-in-user):


            If you get an output like the above, it means logged-in-user already had an active session with private.registry.com. If you are just promoted for username instead, that would indicate that there's no active session.






            share|improve this answer























            • Thanks a lot, this is the best answer
              – Shqear
              Mar 21 at 22:09










            • Yes, this is the best answer, because it provides a way to determine this in a shell script or other program.
              – Teekin
              Jul 7 at 11:05















            up vote
            24
            down vote













            I use one of the following two ways for this check:



            1: View config.json file:



            In case you are logged in to "private.registry.com" you will see an entry for the same as following in ~/.docker/config.json:



            "auths": {
            "private.registry.com": {
            "auth": "gibberishgibberishgibberishgibberishgibberishgibberish"
            }
            }


            2: Try docker login once again:



            If you are trying to see if you already have an active session with private.registry.com, try to login again:



            bash$ docker login private.registry.com
            Username (logged-in-user):


            If you get an output like the above, it means logged-in-user already had an active session with private.registry.com. If you are just promoted for username instead, that would indicate that there's no active session.






            share|improve this answer























            • Thanks a lot, this is the best answer
              – Shqear
              Mar 21 at 22:09










            • Yes, this is the best answer, because it provides a way to determine this in a shell script or other program.
              – Teekin
              Jul 7 at 11:05













            up vote
            24
            down vote










            up vote
            24
            down vote









            I use one of the following two ways for this check:



            1: View config.json file:



            In case you are logged in to "private.registry.com" you will see an entry for the same as following in ~/.docker/config.json:



            "auths": {
            "private.registry.com": {
            "auth": "gibberishgibberishgibberishgibberishgibberishgibberish"
            }
            }


            2: Try docker login once again:



            If you are trying to see if you already have an active session with private.registry.com, try to login again:



            bash$ docker login private.registry.com
            Username (logged-in-user):


            If you get an output like the above, it means logged-in-user already had an active session with private.registry.com. If you are just promoted for username instead, that would indicate that there's no active session.






            share|improve this answer














            I use one of the following two ways for this check:



            1: View config.json file:



            In case you are logged in to "private.registry.com" you will see an entry for the same as following in ~/.docker/config.json:



            "auths": {
            "private.registry.com": {
            "auth": "gibberishgibberishgibberishgibberishgibberishgibberish"
            }
            }


            2: Try docker login once again:



            If you are trying to see if you already have an active session with private.registry.com, try to login again:



            bash$ docker login private.registry.com
            Username (logged-in-user):


            If you get an output like the above, it means logged-in-user already had an active session with private.registry.com. If you are just promoted for username instead, that would indicate that there's no active session.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 22 at 0:50









            Leon Bambrick

            17.5k84371




            17.5k84371










            answered Nov 30 '17 at 19:03









            Arnab

            425411




            425411












            • Thanks a lot, this is the best answer
              – Shqear
              Mar 21 at 22:09










            • Yes, this is the best answer, because it provides a way to determine this in a shell script or other program.
              – Teekin
              Jul 7 at 11:05


















            • Thanks a lot, this is the best answer
              – Shqear
              Mar 21 at 22:09










            • Yes, this is the best answer, because it provides a way to determine this in a shell script or other program.
              – Teekin
              Jul 7 at 11:05
















            Thanks a lot, this is the best answer
            – Shqear
            Mar 21 at 22:09




            Thanks a lot, this is the best answer
            – Shqear
            Mar 21 at 22:09












            Yes, this is the best answer, because it provides a way to determine this in a shell script or other program.
            – Teekin
            Jul 7 at 11:05




            Yes, this is the best answer, because it provides a way to determine this in a shell script or other program.
            – Teekin
            Jul 7 at 11:05










            up vote
            4
            down vote













            For private registries, nothing is shown in docker info. However, the logout command will tell you if you were logged in:



             $ docker logout private.example.com
            Not logged in to private.example.com


            (Though this will force you to log in again.)






            share|improve this answer

























              up vote
              4
              down vote













              For private registries, nothing is shown in docker info. However, the logout command will tell you if you were logged in:



               $ docker logout private.example.com
              Not logged in to private.example.com


              (Though this will force you to log in again.)






              share|improve this answer























                up vote
                4
                down vote










                up vote
                4
                down vote









                For private registries, nothing is shown in docker info. However, the logout command will tell you if you were logged in:



                 $ docker logout private.example.com
                Not logged in to private.example.com


                (Though this will force you to log in again.)






                share|improve this answer












                For private registries, nothing is shown in docker info. However, the logout command will tell you if you were logged in:



                 $ docker logout private.example.com
                Not logged in to private.example.com


                (Though this will force you to log in again.)







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jul 7 '17 at 17:18









                Wilfred Hughes

                16.4k1090128




                16.4k1090128






















                    up vote
                    2
                    down vote













                    At least in "Docker for Windows" you can see if you are logged in to docker hub over the UI. Just right click the docker icon in the windows notification area:
                    Docker Logged in






                    share|improve this answer

























                      up vote
                      2
                      down vote













                      At least in "Docker for Windows" you can see if you are logged in to docker hub over the UI. Just right click the docker icon in the windows notification area:
                      Docker Logged in






                      share|improve this answer























                        up vote
                        2
                        down vote










                        up vote
                        2
                        down vote









                        At least in "Docker for Windows" you can see if you are logged in to docker hub over the UI. Just right click the docker icon in the windows notification area:
                        Docker Logged in






                        share|improve this answer












                        At least in "Docker for Windows" you can see if you are logged in to docker hub over the UI. Just right click the docker icon in the windows notification area:
                        Docker Logged in







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Sep 3 '17 at 8:32









                        BaluJr.

                        292311




                        292311






















                            up vote
                            2
                            down vote













                            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)





                            share|improve this answer





















                            • This is by far the best stratgy: just try a pull, if it fails then it is not logged in (the rest of the logic you have will depend on each use case, but the first try is universally applicable).
                              – Oliver
                              Nov 11 at 6:00










                            • However someone pointed out on github.com/moby/moby/issues/15466 that there are many reasons for failure, not just login issue, yet docker exit status does not allow to differentiate reason for failure. It's still better than the other solutions, but a full solution would require a patch to docker.
                              – Oliver
                              Nov 11 at 6:08















                            up vote
                            2
                            down vote













                            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)





                            share|improve this answer





















                            • This is by far the best stratgy: just try a pull, if it fails then it is not logged in (the rest of the logic you have will depend on each use case, but the first try is universally applicable).
                              – Oliver
                              Nov 11 at 6:00










                            • However someone pointed out on github.com/moby/moby/issues/15466 that there are many reasons for failure, not just login issue, yet docker exit status does not allow to differentiate reason for failure. It's still better than the other solutions, but a full solution would require a patch to docker.
                              – Oliver
                              Nov 11 at 6:08













                            up vote
                            2
                            down vote










                            up vote
                            2
                            down vote









                            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)





                            share|improve this answer












                            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)






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Oct 11 at 23:47









                            Christian

                            20.6k1190140




                            20.6k1190140












                            • This is by far the best stratgy: just try a pull, if it fails then it is not logged in (the rest of the logic you have will depend on each use case, but the first try is universally applicable).
                              – Oliver
                              Nov 11 at 6:00










                            • However someone pointed out on github.com/moby/moby/issues/15466 that there are many reasons for failure, not just login issue, yet docker exit status does not allow to differentiate reason for failure. It's still better than the other solutions, but a full solution would require a patch to docker.
                              – Oliver
                              Nov 11 at 6:08


















                            • This is by far the best stratgy: just try a pull, if it fails then it is not logged in (the rest of the logic you have will depend on each use case, but the first try is universally applicable).
                              – Oliver
                              Nov 11 at 6:00










                            • However someone pointed out on github.com/moby/moby/issues/15466 that there are many reasons for failure, not just login issue, yet docker exit status does not allow to differentiate reason for failure. It's still better than the other solutions, but a full solution would require a patch to docker.
                              – Oliver
                              Nov 11 at 6:08
















                            This is by far the best stratgy: just try a pull, if it fails then it is not logged in (the rest of the logic you have will depend on each use case, but the first try is universally applicable).
                            – Oliver
                            Nov 11 at 6:00




                            This is by far the best stratgy: just try a pull, if it fails then it is not logged in (the rest of the logic you have will depend on each use case, but the first try is universally applicable).
                            – Oliver
                            Nov 11 at 6:00












                            However someone pointed out on github.com/moby/moby/issues/15466 that there are many reasons for failure, not just login issue, yet docker exit status does not allow to differentiate reason for failure. It's still better than the other solutions, but a full solution would require a patch to docker.
                            – Oliver
                            Nov 11 at 6:08




                            However someone pointed out on github.com/moby/moby/issues/15466 that there are many reasons for failure, not just login issue, yet docker exit status does not allow to differentiate reason for failure. It's still better than the other solutions, but a full solution would require a patch to docker.
                            – Oliver
                            Nov 11 at 6:08










                            up vote
                            1
                            down vote













                            Use command like below:



                            docker info | grep 'name'

                            WARNING: No swap limit support
                            Username: <strong>jonasm2009</strong>





                            share|improve this answer



























                              up vote
                              1
                              down vote













                              Use command like below:



                              docker info | grep 'name'

                              WARNING: No swap limit support
                              Username: <strong>jonasm2009</strong>





                              share|improve this answer

























                                up vote
                                1
                                down vote










                                up vote
                                1
                                down vote









                                Use command like below:



                                docker info | grep 'name'

                                WARNING: No swap limit support
                                Username: <strong>jonasm2009</strong>





                                share|improve this answer














                                Use command like below:



                                docker info | grep 'name'

                                WARNING: No swap limit support
                                Username: <strong>jonasm2009</strong>






                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Jul 20 at 17:05









                                xploshioOn

                                2,97311729




                                2,97311729










                                answered Jul 20 at 2:23









                                Meng Jonas

                                112




                                112






















                                    up vote
                                    0
                                    down vote













                                    Just checked, today it looks like this:



                                    $ docker login
                                    Authenticating with existing credentials...
                                    Login Succeeded


                                    NOTE: this is on a macOS with the latest version of Docker CE, docker-credential-helper - both installed with homebrew.






                                    share|improve this answer

























                                      up vote
                                      0
                                      down vote













                                      Just checked, today it looks like this:



                                      $ docker login
                                      Authenticating with existing credentials...
                                      Login Succeeded


                                      NOTE: this is on a macOS with the latest version of Docker CE, docker-credential-helper - both installed with homebrew.






                                      share|improve this answer























                                        up vote
                                        0
                                        down vote










                                        up vote
                                        0
                                        down vote









                                        Just checked, today it looks like this:



                                        $ docker login
                                        Authenticating with existing credentials...
                                        Login Succeeded


                                        NOTE: this is on a macOS with the latest version of Docker CE, docker-credential-helper - both installed with homebrew.






                                        share|improve this answer












                                        Just checked, today it looks like this:



                                        $ docker login
                                        Authenticating with existing credentials...
                                        Login Succeeded


                                        NOTE: this is on a macOS with the latest version of Docker CE, docker-credential-helper - both installed with homebrew.







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Aug 11 at 21:31









                                        todd_dsm

                                        3311517




                                        3311517






















                                            up vote
                                            0
                                            down vote













                                            As pointed out by @Christian, best to try operation first then login only if necessary. Problem is that "if necessary" is not that obvious to do robustly. One approach is to compare the stderr of the docker operation with some strings that are known (by trial and error). For example,



                                            try "docker OPERATION"
                                            if it failed:
                                            capture the stderr of "docker OPERATION"
                                            if it ends with "no basic auth credentials":
                                            try docker login
                                            else if it ends with "not found":
                                            fatal error: image name/tag probably incorrect
                                            else if it ends with <other stuff you care to trap>:
                                            ...
                                            else:
                                            fatal error: unknown cause

                                            try docker OPERATION again
                                            if this fails: you're SOL!





                                            share|improve this answer

























                                              up vote
                                              0
                                              down vote













                                              As pointed out by @Christian, best to try operation first then login only if necessary. Problem is that "if necessary" is not that obvious to do robustly. One approach is to compare the stderr of the docker operation with some strings that are known (by trial and error). For example,



                                              try "docker OPERATION"
                                              if it failed:
                                              capture the stderr of "docker OPERATION"
                                              if it ends with "no basic auth credentials":
                                              try docker login
                                              else if it ends with "not found":
                                              fatal error: image name/tag probably incorrect
                                              else if it ends with <other stuff you care to trap>:
                                              ...
                                              else:
                                              fatal error: unknown cause

                                              try docker OPERATION again
                                              if this fails: you're SOL!





                                              share|improve this answer























                                                up vote
                                                0
                                                down vote










                                                up vote
                                                0
                                                down vote









                                                As pointed out by @Christian, best to try operation first then login only if necessary. Problem is that "if necessary" is not that obvious to do robustly. One approach is to compare the stderr of the docker operation with some strings that are known (by trial and error). For example,



                                                try "docker OPERATION"
                                                if it failed:
                                                capture the stderr of "docker OPERATION"
                                                if it ends with "no basic auth credentials":
                                                try docker login
                                                else if it ends with "not found":
                                                fatal error: image name/tag probably incorrect
                                                else if it ends with <other stuff you care to trap>:
                                                ...
                                                else:
                                                fatal error: unknown cause

                                                try docker OPERATION again
                                                if this fails: you're SOL!





                                                share|improve this answer












                                                As pointed out by @Christian, best to try operation first then login only if necessary. Problem is that "if necessary" is not that obvious to do robustly. One approach is to compare the stderr of the docker operation with some strings that are known (by trial and error). For example,



                                                try "docker OPERATION"
                                                if it failed:
                                                capture the stderr of "docker OPERATION"
                                                if it ends with "no basic auth credentials":
                                                try docker login
                                                else if it ends with "not found":
                                                fatal error: image name/tag probably incorrect
                                                else if it ends with <other stuff you care to trap>:
                                                ...
                                                else:
                                                fatal error: unknown cause

                                                try docker OPERATION again
                                                if this fails: you're SOL!






                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Nov 11 at 7:04









                                                Oliver

                                                15.2k32444




                                                15.2k32444






























                                                     

                                                    draft saved


                                                    draft discarded



















































                                                     


                                                    draft saved


                                                    draft discarded














                                                    StackExchange.ready(
                                                    function () {
                                                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f36022892%2fhow-to-know-if-docker-is-already-logged-in-to-a-docker-registry-server%23new-answer', 'question_page');
                                                    }
                                                    );

                                                    Post as a guest















                                                    Required, but never shown





















































                                                    Required, but never shown














                                                    Required, but never shown












                                                    Required, but never shown







                                                    Required, but never shown

































                                                    Required, but never shown














                                                    Required, but never shown












                                                    Required, but never shown







                                                    Required, but never shown







                                                    Popular posts from this blog

                                                    Bressuire

                                                    Vorschmack

                                                    Quarantine