This is just a short little post on how to manually publish images to GitHub Container Registry (GHCR). Looking at the documentation, the usual way to go seems to be to use GitHub Actions and automatically build and publish images onto the registry. However, I do have one use case where images aren’t built via GitHub Actions but offline on a machine of mine, yet I still want to make the images available via ghcr.io. It took me longer than it should have to figure out how to manually authenticate to ghcr.io, so here are the steps.
Generate Personal Access Token
At first, you might think that you can authenticate with GHCR just by simply using your GitHub username and password. That is not the case. To authenticate you will need a token, a so-called personal access token (PAT). Head over to GitHub and click on the drop-down of your user on the top right. From there, head into Settings
. Then click on Developer settings
at the bottom of the left side. Now click on Personal access token
and from there Generate new token
:

Next, give your token a meaningful name, choose an expiration of your liking and check the write:packages
scope, then hit Generate token
at the bottom of the page:

Make sure you copy your token, you will not be able to see it again!
Login to ghcr.io
The next step is rather straightforward. Head into the command line (or whatever tool you are using) and authenticate with ghcr.io via the usual docker login ghcr.io
or similar methods. Your username is your GitHub username or the organization that you want to publish the image to and your password is the personal access token. On successful login, you should see something like this:
$ podman login ghcr.io
Username: <your GitHub username/organization>
Password: <your personal access token>
Login Succeeded!
Publish images to GHCR
Once logged in, you are ready to publish your images to ghcr.io/<your GitHub username/organization>/<your package name>
, for example:
$ podman push localhost/gvenzl/oracle-xe:latest ghcr.io/gvenzl/oracle-xe:latest