英文:
Pushing to GitHub Container Registry: unauthorized: unauthenticated: User cannot be authenticated with the token provided
问题
当我尝试:
docker push ghcr.io/username/imagename:latest
根据[GitHub文档](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry),我看到
未经授权:未认证:无法使用提供的令牌对用户进行认证。
如何将镜像推送到ghcr?
英文:
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
得分: 3
你需要授予 Docker 权限以推送到你的 GHCR(GitHub 官方文档中提供了具体说明,但可能有点难以找到)。
3个步骤:
-
创建一个访问令牌(PAT)(这里),并给予它读/写 packages权限。
-
复制 PAT 到剪贴板,并在你的终端中运行以下命令:
docker login ghcr.io -u 用户名 -p ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
将用户名
替换为你的 GitHub 用户名,ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
替换为刚刚创建的 PAT。现在 Docker 可以访问你的 GHCR,包括推送的权限。
- 再次尝试你的
push
命令:
docker push ghcr.io/用户名/镜像名称:latest
英文:
You have to give docker permission to push to your GHCR (instructions are in the github docs, but are somewhat buried).
3 Steps:
-
Create an access token (PAT) (here) and give it read/write packages permissions.
-
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.
- Try your
push
command again and it will work:
docker push ghcr.io/username/imagename:latest
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论