To start using a private Docker Registry a user usually should run the docker login
command and set a username and password that will be cached locally.
If a user tries to docker pull
or docker push
an image from/to a private Docker Registry, without having run the docker login
command in advance, he may receive the “unauthorized: authentication required” error.
This guide explains how to log in and how to log out of a private Docker Registry from the command line using the docker login
and docker logout
commands.
Cool Tip: Pull an image from Docker Registry! Read More →
Docker Login Command
By default, if you don’t specify a private registry, the docker login
command will try to log in to a Docker Hub’s public registry located at https://registry-1.docker.io:
$ 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: foo Password:
Log in to a private Docker Registry (you will be prompted for credentials):
$ docker login private.registry.tld:8080 Username: foo Password:
Log in to a private Docker Registry with a username and password passed through the command line:
$ docker login private.registry.tld:8080 -u <username> -p <password>
Alternatively you can read a password from a file, and pass it to the docker login
command using STDIN (handy for automations):
$ cat pwd.txt | docker login private.registry.tld:8080 -u <username> --password-stdin
When you log in, the command stores base64
encoded username:password
pair in $HOME/.docker/config.json
on Linux or %USERPROFILE%/.docker/config.json
on Windows:
$ cat $HOME/.docker/config.json { "auths": { "https://private.registry.tld:8080/v2/": { "auth": "dXNlcm5hbWU6cGFzc3dvcmQ=" } } }
Cool Tip: Enter a running Docker container and start a bash
session! Read More →
Docker Logout Command
The docker logout
command is used to log out of a Docker Registry:
$ docker logout private.registry.tld:8080