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.
- Docker Hub account
- Docker Hub personal access token
Step 1. Login to Docker Hub.
docker login -u <username>
Now, you will be prompted to insert your Docker Hub access token.
- If you have enabled 2FA on your Docker Hub account, you can’t use password anymore.
docker login -u <username> -p <password>or
cat 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.jsonon Linux and macOS, or
Step 2. Push the Docker image again. For instance:
docker push devcoops/goapi:1.2
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.