Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Docker login/logout command

Docker login/logout command

Docker Command ReferenceDocker Command Reference


docker login and docker logout The commands are used to manage authentication between the Docker client and the Docker registry. Through the docker login command, users can log in to a Docker registry, access and push images; through the docker logout command, users can log out.


docker login

docker login The command is used to log in to a Docker registry.

By default, it logs in to Docker Hub, but you can also log in to other Docker registries.

Syntax



docker login [OPTIONS] [SERVER]

Usage examples

1. Log in to Docker Hub

docker login

Prompts you to enter your Docker Hub username and password.

** 2. Log in to Docker Hub (specify username)**



docker login --username myusername

3. Prompts you to enter the Docker Hub password.

Read the password from standard input:



echo "mypassword" | docker login --username myusername --password-stdin

Read the password from standard input to avoid entering it in plain text on the command line.

** 4. Log in to a custom registry**



docker login myregistry.com

Prompts you to enter the username and password for the custom registry.


docker logout

docker logout The command is used to log out of the currently logged-in Docker registry. By default, it logs out of Docker Hub, but you can specify another registry.

Syntax

docker logout [SERVER]

Usage examples

** 1. Log out of Docker Hub**



docker logout

Log out the current user from Docker Hub.

** 2. Log out of a custom registry**



docker logout myregistry.com

Log out the current user from myregistry.com.


Practical examples

1. Log in to Docker Hub

docker login

Output:



Username: myusername

Password: 

Login Succeeded

2. Log in to Docker Hub with the password read from standard input



echo "mypassword" | docker login --username myusername --password-stdin

Output:



Login Succeeded

3. Log in to a custom registry



docker login myregistry.com

Output:



Username: myusername

Password: 

Login Succeeded

4. Log out of Docker Hub



docker logout

Output:



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

5. Log out of a custom registry



docker logout myregistry.com

Output:



Removing login credentials for myregistry.com

Notes


Docker Command ReferenceDocker Command Reference