DEV Community

David MacEachern
David MacEachern

Posted on • Edited on

Using Github Container Registry

Using Docker is common place, it's useful in various points of the SDLC, and solves some headaches when it comes to reproducing a code build on different architectures.

I've been looking at setting up a container registry to enable some experimentation with Kubernetes, which requires having a registry for custom images, whether I will actually do anything with Kubernetes
we will see.

Today I discovered Github has a container registry service (or 'GHCR'), for personal use this is appealing with limits that are not so low that we cannot experiment with them.

Plan Storage Datatransfer out within Actions Datatransfer out without Actions
Free 500MB Unlimited 1GB per month
Pro 2GB Unlimited 10GB per month

Luckily I have Pro plan so let's have a look at what we can do.

Storing a container in the GHCR

First we need to register our github container registry with our Docker client:

  1. Create a token here
  2. Navigate to "https://github.com/" + $YOUR_GITHUB_USER + "?package_type=Docker&tab=packages"
  3. Read the instruction titled # Step 1: Authenticate and understand what it needs, then run this in your shell locally.

Next thing we need is a custom Dockerfile that we can upload to the registry, you can refer to this repository if you're not sure how to proceed.

  1. Create a new Dockerfile in a local directory.
  2. Add the build you want, or stick in hello world build steps to keep it simple, remember we're just here to test out GHCR.
  3. Build the image, if you used the repository I created then you might run docker build -t playground-ghcr:latest .
  4. Then we will want to get the container image id, docker image list, my image was 118MB in size, which is within the limits mentioned previously.
  5. Continue with # Step 2: Tag don't forget to understand what these commands will do that you're being asked to run!
  6. Piping docker image list | grep ghcr should return the image with two tags now (or even more if you made mistakes like me!).
  7. Continue with # Step 3: Publish, as I mentioned before I made a mistake where I didn't swap out the /repository-name/, silly me!

Reviewing usage

So I uploaded an image that was 118MB in size and it took 6m 28s on my slow network speed.

Pulling the image back down should begin using the quota we have on our Github plan.

  1. We can remove the image we have locally docker image rm -f $IMAGE_ID
  2. Then we can request the image we uploaded before from GHCR docker pull docker.pkg.github.com/davidmaceachern/playground-ghcr/playground-ghcr:latest
  3. After we can verify if we wish that this is indeed our Docker image docker container run $IMAGE_ID.
  4. Finally we can navigate here to view billing details.

So a little disappointing, it appears that billing data might not be available until the quota resets Data transfer quota resets in 4 days,
or not at all given that the service is still in public beta:

During the beta, storage and bandwidth is free.
Github

Checking the recently released github cli docs there is no sign of a billing function. Maybe this data could be grabbed using the graphql feature?

What about Dockerhub?

When we compare the experience with Dockerhub for a second, the limits for private repositories appear to be much lower than those provided with the free tier of Dockerhub even after they announced new rate limits for their service.

Vincent kindly pointed out in the comments, that the billing details I referred to are for hidden repositories, Github is offering a very appealing pricing model.

"The limits that you cite are only for private. If your containers are public then there are no limits, even for free accounts."

Docker has however provided a better way to obtain how much usage you have incurred which they explained here

So I will probably continue using the service until the official pricing is announced.

Wrapping up

So there ends a little investigation into using Github Container Registry, it seems like it's still a work in progress for Github but it should do the job for projects going forward.

Feel free to share any thoughts or findings of your own down below if you want 🙏🏻.

Top comments (2)

Collapse
 
cicirello profile image
Vincent A. Cicirello

The limits that you cite are only for private. If your containers are public then there are no limits, even for free accounts.

Collapse
 
davidmaceachern profile image
David MacEachern

Thanks for verifying that Vincent! I have updated the post to reflect this.