Github Docker pull error from github registry Error response from daemon: unauthorized

Viewed 43

Can anyone explain what else I would need to authorize a pull from a private . I have followed the docs and still getting this error:

Error response from daemon: Head "https://ghcr.io/v2/my-image/manifests/latest": unauthorized

I have seen other developers on here having similar issues which I have tried their solutions but still not working. Based on the docs there are 2 ways to authenticate. The old and not recommend anymore according to docs is using a PAT personal access token. The second way and recommend is using a secrets.GITHUB_TOKEN as shown here I'm using the GITHUB_TOKEN setup as seen in my code below.

What am I missing here to be able to do a pull on the package after it has pushed to the registry ??

github workflow

name: Release
on:
  push:
    branches:
      - main
env:
  REGISTRY: ghcr.io
  IMAGE_NAME: ${{ github.repository }}

jobs:
  Release:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Log into Container registry ${{ env.REGISTRY }}
        uses: docker/login-action@v2
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Extract metadata (tags, labels) for Docker
        id: meta
        uses: docker/metadata-action@v4
        with:
          images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

      - name: Build and push Docker image
        uses: docker/build-push-action@v3
        with:
          context: .
          push: true
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}

Workflow permissionsenter image description here:

1 Answers

For anyone else who has this issue maybe this will help: 2 extra steps to the above post.

  1. Delete the package that I had already created in github
  2. Then run another build using a PAT that I created.

Github action updated code:

  - name: Log into Container registry ${{ env.REGISTRY }}
    uses: docker/login-action@v2
    with:
      registry: ${{ env.REGISTRY }}
      username: ${{ github.actor }}
      password: ${{ secrets.GITHUB_PAT }}

After doing a new build I had to login to docker using the PAT as the password.

docker login ghcr.io --username YOUR_GITHUB_USERNAME
Related