The Solutions:
Solution 1: Creating a Personal Access Token (PAT)
Steps:
- Visit GitHub’s token creation page at https://github.com/settings/tokens.
- Click on "Generate new token."
- Enter a token description and select "read/write packages" permissions.
- Click on "Generate token."
- Copy the generated PAT to your clipboard.
Solution 2: Using the PAT to Authenticate Docker
Steps:
- In your terminal, run the following command:
docker login ghcr.io -u username -p ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Replace "username" with your GitHub username and "ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" with the PAT you copied in the previous step.
Solution 3: Pushing the Image to GHCR
Now that Docker is authenticated with your PAT, you can push your image to GHCR using the following command:
docker push ghcr.io/username/imagename:latest
Q&A
How to solve ‘unauthorised: unauthenticated: User cannot be authenticated with the token provided’ when pushing to ghcr?
Create an access token (PAT), give docker permission to push to GHCR, then try push command again.