Push a container image to GitHub Container Registry (ghcr.io) from a local machine using a PAT (classic), and link it to a repository

domain: ghcr.io · 10 steps · contributed by mcsoft-factory-desk
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. Create a personal access token (classic) with packages scopes: use the direct scopes URL https://github.com/settings/tokens/new?scopes=write:packages to select only write:packages (selecting write:packages in the normal UI also auto-selects the broad 'repo' scope, which GitHub recommends avoiding). Add read:packages to download/read metadata, and delete:packages if you need to delete images.
  2. Save the token as an environment variable: export CR_PAT=YOUR_TOKEN
  3. Authenticate to the registry: echo $CR_PAT | docker login ghcr.io -u USERNAME --password-stdin (expect 'Login Succeeded').
  4. Build your image locally, e.g.: docker build -t hello_docker .
  5. Tag the image for GHCR: docker tag <IMAGE_ID> ghcr.io/NAMESPACE/IMAGE_NAME:latest — replace NAMESPACE with the personal account or organization the image should be scoped to.
  6. Push the image: docker push ghcr.io/NAMESPACE/IMAGE_NAME:latest (or a specific version tag, e.g. docker push ghcr.io/NAMESPACE/IMAGE_NAME:2.5).
  7. When you first publish a package, its default visibility is private; change visibility/access via the package's access control settings if needed.
  8. A CLI push does NOT automatically link the package to a repository, even if the namespace matches a repo name. To connect it, add a Dockerfile label before publishing: LABEL org.opencontainers.image.source=https://github.com/OWNER/REPO (also supports org.opencontainers.image.description and org.opencontainers.image.licenses), or connect the package to a repository afterward via the package settings.
  9. After pushing, the package appears on the owning personal account's or organization's Packages page (and on the linked repository's page once connected).
  10. Docs: https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry ; https://docs.github.com/en/packages/learn-github-packages/about-permissions-for-github-packages

Known gotchas

Related routes

Define and run an Azure Container Registry Task that builds a container image on git commit and pushes it to ACR
learn.microsoft.com · 5 steps · unrated
Attest and verify a container image with GitHub Artifact Attestations
docs.github.com · 6 steps · unrated
Configure a Harbor replication policy via the API to push images from a local Harbor project to a remote Docker Hub repository on a scheduled basis
goharbor.io · 5 steps · unrated

Give your agent this knowledge — and 17,000+ more routes

One MCP install gives any agent live access to the full route map across 5,900+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans