Docker

How to Login into Docker via Command Prompt?

Docker is a well-known development forum utilized for project development. It offers multiple important components like Docker images, containers, Docker registries, etc. It also provides an official Docker registry, such as Docker Hub, that has official Docker images. To use Docker Hub, users need to create a new account or log in to an already created account. Moreover, users can also log in to Docker Hub using the command line.

This write-up will explain the method to login into Docker via Command Prompt:

How to Login into Docker (Official Registry) via Command Prompt?

Before logging into Docker via Command Prompt, users must have a Docker account. So, create an account on Docker Hub first. After creating the account, follow the provided steps to login into Docker:

Step 1: Launch Command Prompt

From the Start menu, search for the “Command Prompt” and launch it:

Step 2: Log in to Docker (Official Registry)

Run the below-listed command in the Command Prompt and provide the required username and password to log in to Docker:

docker login

The output indicates that we have been logged in successfully after providing the required credentials.

Alternatively, the “-u” and “-p” options can also be utilized with the “docker login” command to specify the username and password directly in the command to log in:

docker login -u <user-name> -p <password>

How to Login into Docker (Private Registry) via Command Prompt?

If you’re using a private Docker registry, use the “docker login” command along with the registry domain or URL. Here, “localhost:5000” is our registry’s URL:

docker login localhost:5000

The output shows that we have successfully logged in after the required credentials.

Alternatively, users can specify the username and password using “-u” and “-p” flags with the “docker login” command and registry URL to perform the same operation:

docker login localhost:5000 -u <user-name> -p <password>

Once you have successfully logged in to Docker, you will be able to push and pull Docker images to and from your public or private registry.

Bonus Tip: Logout Docker

To log out from the Docker official registry, utilize the below-listed command:

docker logout

Moreover, to log out from the private registry, specify the registry domain or URL with the “docker logout” command. For instance, we have specified the “localhost:5000” registry domain:

docker logout localhost:5000

The above outputs show that we have successfully logged out from the Docker registries.

Conclusion

To login into Docker official registry via Command Prompt, first, launch Command Prompt. Then, execute the “docker login” or “docker login -u <user-name> -p <password>” command. After that, provide the required username and password to log in to Docker. In the case of the Docker private registry, specify the registry domain or URL in the same commands to log in to Docker. This write-up has described the method to login into Docker via Command Prompt.

About the author

Laiba Younas

I have done bachelors in Computer Science. Being passionate about learning new technologies, I am interested in exploring different programming languages and sharing my experience with the world.