Docker login/logout command

Docker command reference


docker loginanddocker logoutThe command is used to manage authentication between the Docker client and Docker registry. Throughdocker logincommand, users can log in to a Docker registry to access and push images; throughdocker logoutCommand, user can log out.

  • docker login :Log in to a Docker image registry. If no registry address is specified, the default is the official registry Docker Hub.

  • docker logout :Log out of a Docker image registry. If no registry address is specified, the default is the official registry Docker Hub.


docker login

docker loginThe command is used to log in to a Docker registry.

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

Syntax

docker login [OPTIONS] [SERVER]
  • SERVER: The server address of the Docker registry (default is Docker Hub).

  • -u, --username: Login username.
  • -p, --password: Login password (not recommended to use on the command line).
  • --password-stdin: Read the password from standard input.

Usage examples

1. Log in to Docker Hub

docker login

Prompt for Docker Hub username and password.

2. Log in to Docker Hub (specify username)

docker login --username myusername

3. Prompt for 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 the password in plaintext on the command line.

4. Login to custom registry

docker login myregistry.com

Prompt for the username and password of a custom registry.


docker logout

docker logoutThe command is used to log out of the currently logged-in Docker registry. By default, it logs out of Docker Hub, but another registry can also be specified.

Syntax

docker logout [SERVER]
  • SERVER: The server address of the Docker registry (default is Docker Hub).

Usage examples

1. Log out of Docker Hub

docker logout

Log out the current user's login state on Docker Hub.

2. Logout from custom registry

docker logout myregistry.com

Log out the current user's login state on myregistry.com.


Operation examples

1. Log in to Docker Hub

docker login

Output:

Username: myusername
Password: 
Login Succeeded

2. Log in to Docker Hub by reading the password from standard input

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

Output:

Login Succeeded

3. Login to 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. Logout from custom registry

docker logout myregistry.com

Output:

Removing login credentials for myregistry.com

Notes

  • Not recommended for direct use in the command line-pOption to enter the password, because this way the password would be exposed in plaintext in the command history.
  • Usage--password-stdinThis can avoid plaintext exposure of the password and enhance security.
  • Ensure execution in a public or shared environment.docker logout, to prevent other users from accessing your account.

Docker command reference

other extensions