Skip to main content
Removed obsolete and uneccesary text to enhance readability
Source Link

For the original post and resolution mentioned here check: this question: how can I tell if I'm logged into a private docker registry which is also posted as an answer on this question in one of the answers below.

Initial post: check login status by running login command

Alternative method (re-login)

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:

[[email protected] ~]$ 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 For the comments of thisoriginal explanation for the ~/.docker/config.json, check question: how can I tell if I'm logged into a private docker registry

For the original post and resolution mentioned here check: this question: how can I tell if I'm logged into a private docker registry which is also posted as an answer on this question in one of the answers below.

Initial post: check login status by running login command

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:

[[email protected] ~]$ 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

Alternative method (re-login)

For the original explanation for the ~/.docker/config.json, check question: how can I tell if I'm logged into a private docker registry

Removed the "however" as the quote already implies it is stored on disk.
Source Link

Edit 2020

Referring back to the (closed) github issue, where it is pointed out, there is no actual session or state;

docker login actually isn't creating any sort of persistent session, it is only storing the user's credentials on disk so that when authentication is required it can read them to login

However, asAs others have pointed out, an auths entry/node is added to the ~/.docker/config.json file (this also works for private registries) after you succesfully login:

{
    "auths": {
            "https://index.docker.io/v1/": {}
    },
    ...

When logging out, this entry is then removed:

$ docker logout
Removing login credentials for https://index.docker.io/v1/

Content of docker config.json after:

{
    "auths": {},
    ...

This file can be parsed by your script or code to check your login status.

For the original post and resolution mentioned here check: this question: how can I tell if I'm logged into a private docker registry which is also posted as an answer on this question in one of the answers below.

Initial post: check login status by running login command

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):        # <-- "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:

[[email protected] ~]$ 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

Edit 2020

Referring back to the (closed) github issue, where it is pointed out, there is no actual session or state;

docker login actually isn't creating any sort of persistent session, it is only storing the user's credentials on disk so that when authentication is required it can read them to login

However, as others have pointed out, an auths entry/node is added to the ~/.docker/config.json file (this also works for private registries) after you succesfully login:

{
    "auths": {
            "https://index.docker.io/v1/": {}
    },
    ...

When logging out, this entry is then removed:

$ docker logout
Removing login credentials for https://index.docker.io/v1/

Content of docker config.json after:

{
    "auths": {},
    ...

This file can be parsed by your script or code to check your login status.

For the original post and resolution mentioned here check: this question: how can I tell if I'm logged into a private docker registry which is also posted as an answer on this question in one of the answers below.

Initial post: check login status by running login command

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):        # <-- "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:

[[email protected] ~]$ 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

Edit 2020

Referring back to the (closed) github issue, where it is pointed out, there is no actual session or state;

docker login actually isn't creating any sort of persistent session, it is only storing the user's credentials on disk so that when authentication is required it can read them to login

As others have pointed out, an auths entry/node is added to the ~/.docker/config.json file (this also works for private registries) after you succesfully login:

{
    "auths": {
            "https://index.docker.io/v1/": {}
    },
    ...

When logging out, this entry is then removed:

$ docker logout
Removing login credentials for https://index.docker.io/v1/

Content of docker config.json after:

{
    "auths": {},
    ...

This file can be parsed by your script or code to check your login status.

For the original post and resolution mentioned here check: this question: how can I tell if I'm logged into a private docker registry which is also posted as an answer on this question in one of the answers below.

Initial post: check login status by running login command

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):        # <-- "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:

[[email protected] ~]$ 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

Included ellipsis to show file below continues with more content which is irrelevant to the post (and hence excluded)
Source Link
{
        "auths": {
                "https://index.docker.io/v1/": {}
    },
    },...

Content of docker config.json after:

cat ~/.docker/config.json
{
        "auths": {},
    ...
{
        "auths": {
                "https://index.docker.io/v1/": {}
        },
cat ~/.docker/config.json
{
        "auths": {},
{
    "auths": {
            "https://index.docker.io/v1/": {}
    },
    ...

Content of docker config.json after:

{
    "auths": {},
    ...
added 4 characters in body
Source Link
Loading
added 1519 characters in body
Source Link
Loading
added 1519 characters in body
Source Link
Loading
added 663 characters in body
Source Link
Loading
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot
Loading
Corrected answer with note it works only for a specific registry
Source Link
Loading
Source Link
Loading