Home > Software engineering >  Buildx authorization error when trying to release a Docker image to GHCR
Buildx authorization error when trying to release a Docker image to GHCR

Time:05-04

I'm getting this error:

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

after this GitHub Action finishes building the Docker image:

# 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

It's configured following the guide linked at the top of the document. Why would this error occur here?

CodePudding user response:

Try updating the cache-from and cache-to cache references to ghcr.io/t145/black-mirror. When you omit the registry (ghcr.io), I believe it defaults to DockerHub.

  • Related