Docker Login: Authenticating to a Container Registry
docker login saves your credentials for a container registry, letting you push and pull private images. Use it before interacting with private repos on Docker Hub, ECR, or GCR. The footgun: credentials are often stored unencrypted by default.
WHY IT EXISTS: Public container registries are great, but most real-world applications use private images containing proprietary code or sensitive configurations. To control access, these private registries require authentication. docker login provides a standard way for developers to prove their identity from the command line.
THE MENTAL MODEL: Think of docker login as saving your username and password in a browser. Once you log in to a website (like Docker Hub), the browser remembers you. Similarly, docker login saves an authentication token for a specific registry, allowing subsequent Docker commands (push, pull) to access it without asking for credentials every time.
HOW IT WORKS: When you run docker login [SERVER], Docker prompts you for a username and password. Upon successful authentication with the registry's server, the registry returns an authorization token. Docker then stores this token, typically base64-encoded, in the ~/.docker/config.json file on your local machine. Future commands that interact with that registry will automatically include this token in their API requests to authenticate you.
WHEN TO USE IT: Use docker login before your first docker push to a private repository on Docker Hub, or before pulling an image from any private registry like AWS Elastic Container Registry (ECR), Google Container Registry (GCR), or a self-hosted one. It's a one-time setup step per machine, though tokens may expire and require you to log in again.
WHEN NOT TO USE IT: Avoid using docker login with a username and password directly in automated CI/CD pipelines. This can expose credentials in build logs. Instead, use access tokens or service account credentials designed for automation, often passed as environment variables or through the cloud provider's CLI.
ONE CANONICAL EXAMPLE: To log in to the default Docker Hub registry, you simply run docker login. It will prompt for your Docker ID and password. To log in to a different registry, like Google's, you would specify the server: docker login gcr.io.
Read the original → docs.docker.com
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.