Pushing to GitHub Container Registry: unauthorized: unauthenticated: User cannot be authenticated with the token provided
Asked Answered
N

2

7

When I try:

docker push ghcr.io/username/imagename:latest 

as per GitHub docs, I see

unauthorised: unauthenticated: User cannot be authenticated with the token provided.

How do I push the image to ghcr?

Noellanoelle answered 4/4, 2023 at 0:12 Comment(0)
N
10

You have to give docker permission to push to your GHCR (instructions are in the github docs, but are somewhat buried).

3 Steps:

  1. Create an access token (PAT) (here) and give it read/write packages permissions.

  2. Copy the PAT to clipboard, and run this in your terminal:

docker login ghcr.io -u username -p ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

replacing username with your GitHub username, and ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx with the PAT you just made. Now docker has access to your GHCR, including the ability to push.

  1. Try your push command again and it will work:
docker push ghcr.io/username/imagename:latest 
Noellanoelle answered 4/4, 2023 at 0:12 Comment(0)
W
0

You need to grant Docker the necessary permission to push your GitHub container Registry (GHCR). The following steps worked for me.

Step 01

Generate a Personal Access Token (PAT) with permissions to read and write packages.

You can create one Here

Step 02

Copy the PAT and execute the following command in your terminal

docker login --username username --password  YOUR_PAT  ghcr.io

Make sure to replace username with your GitHub username and YOUR_PAT with the token you just generated. This will authenticate Docker with your GHCR for pushing images.

Step 03

Run your push command again

docker push ghcr.io/username/imagename:latest

After completing these steps, you should be able to push your image successfully!

Winebibber answered 25/9 at 11:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.