It’s all fun and games to build and run Docker images on your local machine, but when it comes to pushing to a remote registry, the authentication itself is a pain to dealt with. And here I am with yet another error: unauthorized: authentication required
.
Prerequisites
- Docker
- Docker Hub account
- Docker Hub personal access token
Solution
Step 1. Login to Docker Hub.
docker login -u <username>
Now, you will be prompted to insert your Docker Hub access token.
Note(s):
- If you have enabled 2FA on your Docker Hub account, you can’t use password anymore.
- Running:
docker login -u <username> -p <password>
orcat dockersecret.txt | docker login -u <username> --password-stdin
, will simply fail leading to:Error response from daemon: Get "https://registry-1.docker.io/v2/": unauthorized: please use personal access token to login
. - Personal access tokens are the preferred way to authenticate as they provide certain advantages over passwords, including: non-admin account permission scopes for repos, usage statistics and activities.
- You can find more info about the Docker credentials and credsStore under
$HOME/.docker/config.json
on Linux and macOS, or%USERPROFILE%/.docker/config.json
on Windows.
Step 2. Push the Docker image again. For instance:
docker push devcoops/goapi:1.2
Conclusion
If you have another great solution feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.