[FAQ] GHCR push returns denied in GitHub Actions even with packages: write

未关闭 适合新手
#550 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
1/5
预计耗时
1 小时以内
新手友好度
86/100
Issue 类型
文档
描述清晰度
描述清楚
活跃度
活跃
技术栈
docker, github-actions

调研方向

阅读 repository 中的 FAQ 条目,并将其中的故障排查步骤和重试示例与链接的 .github/workflows/cd.yml 进行比较。确认措辞区分了观察到的首次 push 失败与通常由权限和命名导致的问题;当答案清晰且示例指向可正常工作的 workflow 时,即为完成。

由索引模型根据 Issue 内容生成。

描述

Course

ai-dev-tools-zoomcamp

Question

Final project CI/CD: my GitHub Actions workflow gets denied when pushing a new image to GHCR, even though it has packages: write and docker login succeeds. How do I fix it?

Answer

Re-run the job, and add a retry to the push. In my project the first push of each brand-new package failed, and the same push succeeded on the re-run, with no change to the workflow.

What the log looked like. The layers upload, then the push fails:

ae51df8ce05a: Pushed
error from registry: denied
denied

I had two images, and each one failed once. The first run failed on the API image. The re-run published it and then failed on the frontend image. The third run published both. Later pushes to the same packages had no problem.

Before assuming that's your issue, check the usual causes of denied:

  1. The workflow or job has permissions: packages: write. The default token may be read-only.
  2. The image name uses your own lowercase owner: ghcr.io/<owner>/<name>.
  3. docker/login-action uses password: ${{ secrets.GITHUB_TOKEN }}, and the log shows Login Succeeded!.

If all three are fine and the package doesn't exist yet, retry so a fresh setup doesn't need a manual re-run:

for attempt in 1 2 3; do
  docker push --all-tags "$repository" && break
  [ "$attempt" = 3 ] && exit 1
  sleep 15
done

I don't know the exact cause on GitHub's side. This is what I observed, on a public repository with a user-owned package.

Working example: https://github.com/devotuoma/chamaledger/blob/main/.github/workflows/cd.yml

Checklist
  • I have searched existing FAQs and this question is not already answered
  • The answer provides accurate, helpful information
  • I have included any relevant code examples or links
主要语言
Python
星标
8
派生
20
平均合并
4 天 8 小时
30 天内合并 PR
28

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

DataTalksClub/faq 的其他 Issue

查看 DataTalksClub/faq 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。