Skip to content

Instantly share code, notes, and snippets.

@garnajee
Forked from yokawasa/ghcr.md
Last active May 20, 2024 12:24
Show Gist options
  • Save garnajee/873cc26389cb21d07b19c2dd8150b2f0 to your computer and use it in GitHub Desktop.
Save garnajee/873cc26389cb21d07b19c2dd8150b2f0 to your computer and use it in GitHub Desktop.
ghcr (GitHub Container Registry)

ghcr (GitHub Container Registry) quickstart

CLI

To push container images to ghcr, you need peronal access token (PAT) - see how to create PAT

  1. Get PAT (personal access token)
  2. use thess permissions: repo, write:packages
  3. export PAT: export CR_PAT=YOUR_TOKEN

Personal Settings > Developer settings > Personal access tokens

  1. ghcr login test
echo $CR_PAT | docker login ghcr.io -u garnajee --password-stdin

Login Succeeded
  1. build
docker build -t ghcr.io/garnajee/myrepo/mycontainer:0.0.1 .
  1. push
# docker tag mycontainer ghcr.io/yokawasa/myrepo/mycontainer:0.0.1
docker push ghcr.io/garnajee/myrepo/mycontainer:0.0.1
  1. inspect
docker inspect ghcr.io/garnajee/myrepo/mycontainer:0.0.1

GitHub Actions

you can do seamless access to containers from Actions workflows via the GITHUB_TOKEN

The Container registry supports the GITHUB_TOKEN for easy and secure authentication in your workflows. If your workflow is using a personal access token (PAT) to authenticate to ghcr.io, then we highly recommend you update your workflow to use the GITHUB_TOKEN.

     - name: Log in to registry
        # This is where you will update the PAT to GITHUB_TOKEN
        run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

See Upgrading a workflow that accesses ghcr.io for more detail

Associate a certain package to a repository

REFERENCES

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment