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?

1

There are 1 best solutions below

0
On

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