尝试向 GHCR 发布 Docker 图像时出现 Buildx 授权错误

Buildx authorization error when trying to release a Docker image to GHCR

我收到这个错误:

error: failed to solve: error writing layer blob: server message: insufficient_scope: authorization failed

在此 GitHub 操作完成构建 Docker 图像后:

# https://docs.docker.com/ci-cd/github-actions/
name: Publish Docker Image

on:
  workflow_dispatch:
  push:
    branches:
      - master
    paths:
      - "Dockerfile"
  schedule:
    - cron: "0 6 * * */3"

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repo
        uses: actions/checkout@v3
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v1
      - name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v1
      - name: Login to Docker Hub
        uses: docker/login-action@v1
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ github.token }}
      - name: Build and push
        uses: docker/build-push-action@v2
        with:
          context: ./
          file: ./Dockerfile
          builder: ${{ steps.buildx.outputs.name }}
          push: true
          tags: ghcr.io/t145/black-mirror:latest
          cache-from: type=registry,ref=t145/black-mirror:buildcache
          cache-to: type=registry,ref=t145/black-mirror:buildcache,mode=max

它是按照文档顶部链接的指南配置的。为什么这里会出现这个错误?

尝试更新 cache-fromcache-to 对 ghcr.io/t145/black-mirror 的缓存引用。当您省略注册表时 (ghcr.io),我相信它默认为 DockerHub。