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

Đang mở Phù hợp với người mới
#550 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
1/5
Thời gian dự kiến
Dưới một giờ
Mức phù hợp với người mới
86/100
Loại issue
Tài liệu
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
docker, github-actions
Lĩnh vực
devops, documentation

Hướng nghiên cứu

Đọc mục FAQ trong repository và so sánh các bước khắc phục sự cố cùng ví dụ thử lại với .github/workflows/cd.yml được liên kết. Xác nhận cách diễn đạt phân biệt lỗi push đầu tiên đã quan sát được với các nguyên nhân thường gặp liên quan đến quyền và cách đặt tên; hoàn tất khi câu trả lời rõ ràng và ví dụ trỏ đến workflow đang hoạt động.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
Python
Star
8
Fork
20
Merge trung bình
3 ngày 14 giờ
Pull request đã merge (30 ngày)
3

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của DataTalksClub/faq

Tất cả issue của DataTalksClub/faq

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.