Skip to content

Instantly share code, notes, and snippets.

@magnetikonline
Last active December 10, 2023 10:53
Show Gist options
  • Save magnetikonline/3b86355b5b4f951a732ea2072b6190b5 to your computer and use it in GitHub Desktop.
Save magnetikonline/3b86355b5b4f951a732ea2072b6190b5 to your computer and use it in GitHub Desktop.
Quick example for using the GitHub Container (Docker) registry.

Quick example for using the GitHub Container registry

Human user access

Create a new Personal access token with the following permissions:

delete:packages
read:packages
write:packages

Make a note of the access token returned.

Next, use access token with docker login, where USERNAME is your GitHub username:

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

To push an image, where OWNER is your username/organisation name:

$ docker tag IMAGE_NAME:TAG_NAME ghcr.io/OWNER/IMAGE_NAME:TAG_NAME
$ docker push ghcr.io/OWNER/IMAGE_NAME:TAG_NAME

docker login within a GitHub Actions workflow

Where a Container registry package has been shared to a GitHub repository, executred workflows within this repository now automatically gain access. From within a workflow run step:

- name: Login to Container registry
  run: |
    echo "${{ secrets.GITHUB_TOKEN }}" | \
      docker login ghcr.io -u "${{ github.actor }}" --password-stdin

Reference

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