In this blog post, I would like to show you how easy is to publish your docker images to GitHub Container Registry. This topic is relevant because Docker Hub has changed retention limits, so might want to consider other players on the market.
TL;DR
To publish an image to ghcr:
- Create a Personal Access Token
- Log-in to the container registry
- Push an image to
ghcr.io/GITHUB_USERNAME/IMAGE_NAME:VERSION
To access GitHub container registry you need to create Personal Access Token (PAT) on GitHub:
“Settings > Developer Settings > Personal access tokens” and create token with permissions related to “packages” (or https://github.com/settings/tokens/new).
After that, you can login export CR_PAT=YOUR_TOKEN ; echo $CR_PAT | docker login ghcr.io -u USERNAME --password-stdin
.
Now, you want to tag your local images:
docker tag SOURCE_IMAGE_NAME:VERSION ghcr.io/TARGET_OWNER/TARGET_IMAGE_NAME:VERSION
Push re-tagged imaged to the container registry (ghcr.io):
docker push ghcr.io/OWNER/IMAGE_NAME:VERSION
Example
I’ve pushed a containerized image of dotnet-script to GitHub Registry, it allows you to run REPL-style prompt for C#.
For now, GitHub doesn’t provide search and discovery capabilities for images, but you already can find some UI to see image details from UI, if you know the name.
You can find packaged dotnet-script here:
https://github.com/users/NikiforovAll/packages/container/package/dotnet-script
🚀 Let’s download and run it:
docker image pull ghcr.io/nikiforovall/dotnet-script:latest
docker container run --it --rm ghcr.io/nikiforovall/dotnet-script