Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

docker pull or push to ghcr.io fails with 'denied'

ErrorError response from daemon: denied

Short answer

ghcr.io refuses a pull or push when Docker is not logged in, when the token lacks the package scope, or when the workflow's GITHUB_TOKEN has no packages permission or no access to that package. Private is the default visibility for a new package, so an anonymous pull of it is denied.

  • Applies to GitHub Container registry, docker/login-action, GitHub Actions
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Log in to the registry explicitly, then repeat the pull. If it works, the problem was authentication; if not, continue with the scope and access causes.

    echo $CR_PAT | docker login ghcr.io -u USERNAME --password-stdin
  2. 2Match what you see, then jump to its fix

    1. 1docker pull ghcr.io/NAMESPACE/IMAGE_NAME is denied on a machine or job that never ran docker login.Docker is not logged in to ghcr.io (and the package is private)Fix
    2. 2Login succeeds, but the pull or push is still denied.The personal access token has no package scopeFix
    3. 3docker push from a workflow is denied, and the workflow limits permissions.The workflow's GITHUB_TOKEN has no packages permissionFix
    4. 4The package already exists (for example it was first pushed by hand) and the workflow's push or pull is denied.The repository has no Actions access to an existing packageFix

What does the error look like?

  • Error response from daemon: denied

Cause 1 of 4

Docker is not logged in to ghcr.io (and the package is private)

1Check

A newly published package is private by default, and you need an access token to pull private, internal or public packages through Docker's login.

docker pull ghcr.io/NAMESPACE/IMAGE_NAME

2Fix

Store a classic personal access token in an environment variable and log in with it, or in a workflow use docker/login-action with the GITHUB_TOKEN.

export CR_PAT=YOUR_TOKEN
echo $CR_PAT | docker login ghcr.io -u USERNAME --password-stdin

3Verify

The pull succeeds.

docker pull ghcr.io/NAMESPACE/IMAGE_NAME

Confirmed by docs.github.com

Did this fix it?

Cause 2 of 4

The personal access token has no package scope

1Check

A classic token needs read:packages to download images and write:packages to upload them.

# GitHub, Settings, Developer settings, Personal access tokens: read the scopes

2Fix

Create a classic token with the scope you need. The write:packages scope also selects repo by default in the web form; the docs give a URL that preselects only the package scope.

# https://github.com/settings/tokens/new?scopes=write:packages

3Verify

Log in with the new token and repeat the command.

echo $CR_PAT | docker login ghcr.io -u USERNAME --password-stdin

Confirmed by docs.github.com

Did this fix it?

Cause 3 of 4

The workflow's GITHUB_TOKEN has no packages permission

1Check

For registries with repository-scoped permissions, the docs recommend read for contents and write for packages.

grep -n -A4 "permissions:" .github/workflows/*.yml

2Fix

Set the permissions on the job and log in with the token.

permissions:
  contents: read
  packages: write
steps:
  - uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
    with:
      registry: ghcr.io
      username: ${{ github.actor }}
      password: ${{ secrets.GITHUB_TOKEN }}

3Verify

Re-run the job; the push step passes.

gh run watch --exit-status

Confirmed by docs.github.com

Did this fix it?

Cause 4 of 4

The repository has no Actions access to an existing package

1Check

A workflow can only use a package once its repository is added in the package settings under Manage Actions access.

# Package page, Package settings, Manage Actions access

2Fix

Click Add repository, choose the workflow's repository, and set a role that allows what the workflow does.

# Package settings > Manage Actions access > Add repository

3Verify

Re-run the failed job.

gh run watch --exit-status

Confirmed by docs.github.com

Did this fix it?

How do I stop it coming back?

  • Use the GITHUB_TOKEN with an explicit packages permission in workflows instead of a long-lived personal token.
  • Pull by name for tags and by digest when you need a fixed version.
  • Decide package visibility on purpose after the first publish, since the default is private.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Servers

A GitHub Actions workflow builds the Docker image but cannot push it

The push step fails right after the login step

Four things stop a push from GitHub Actions: build-push-action does not push unless push is true, the Docker Hub login used a password instead of an access token, the workflow token lacks packages write for ghcr.io, or the run comes from a fork, where the token is read-only.

4 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.