Using Github Container Registry
Tags: git, github
Published: 2020-11-07 13:11:35

---
title: Using Github Container Registry
published: true
tags: git, github
---

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](https://github.com/settings/tokens)
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](https://github.com/davidmaceachern/playground-ghcr) if you're not sure how to proceed.

4. Create a new Dockerfile in a local directory.
5. 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.
6. Build the image, if you used the repository I created then you might run `docker build -t playground-ghcr:latest .`
7. 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.
8. Continue with `# Step 2: Tag` don't forget to understand what these commands will do that you're being asked to run!
9. Piping `docker image list | grep ghcr` should return the image with two tags now (or even more if you made mistakes like me!).
10. 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](https://github.com/settings/billing) 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](https://docs.github.com/en/free-pro-team@latest/packages/getting-started-with-github-container-registry/about-github-container-registry)

Checking the recently released github cli [docs](https://cli.github.com/manual/) there is no sign of a billing function. Maybe this data could be grabbed using the [graphql](https://cli.github.com/manual/gh_api) 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](https://www.docker.com/increase-rate-limits) 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](https://www.docker.com/blog/checking-your-current-docker-pull-rate-limits-and-status/)

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 🙏🏻.