docker,

Docker: Error response from daemon: ... unauthorized: please use personal access token to login

Dec 04, 2022 · 2 mins read · Post a comment

Last week I’ve leveled up my security game by reviewing and updating all internet services that I’m using and subscribed to, to enable 2FA, including Docker. After few days, as I was trying to push a Docker image to my Docker Hub repo, I’ve encountered the following error: Error response from daemon: Get "https://registry-1.docker.io/v2/": unauthorized: please use personal access token to login. Here’s what went wrong.

Docker Hub personal access token and access token are used interchangeably.

Prerequisites

  • Docker
  • Docker Hub account

Solution

Apparently, if 2FA is enabled, you must use a personal access token instead of a password. Now, why personal access tokens you might ask, right. Well, personal access tokens are preferred over passwords since the former ones have certain advantages, including: non-admin account permissions, or “better-grained” access permission than using an account password if you will, usage statistics and activity tracking.

Step 1. Create a Docker Hub access token:

Login to Docker Hub -> Account Settings -> Security -> New Access Token

Step 2. Add a description, choose the Access permissions depending on your use case scenario as I would suggest to stick to the least privilege access best practices, and click Generate.

Step 3. Copy the freshly generated access token and store it somewhere securely, hoping you won’t save it in a plane text file lol. At least use some password manager of your liking such as the open-source Bitwarden, or even LastPass.

Step 4. Login to Docker Hub.

docker login -u <username> 

Now, insert your Docker Hub personal access token.

On a side note, if you are more eager to figure some things out about the Docker authentication, how credentials are stored and where to find them, start with the $HOME/.docker/config.json file on Linux and macOS, or %USERPROFILE%/.docker/config.json on Windows.

Step 5. Try pushing the Docker image again. Example:

docker push devcoops/api:1.3

Conclusion

Related post: Docker: unauthorized: authentication required.

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.