Early this month GitHub announced the new GitHub Container Registry service. This service is similar to Docker Hub and GitHub’s own Package Registry. In this post I am going to explain why you should use GitHub’s Container Registry, describe how to create a GitHub Action to automatically build and push Docker images to GitHub’s Container Registry and how use these Docker images in your Kubernetes cluster.


Table of Contents

— Why use GitHub’s Container Registry instead of Docker Hub?

— GitHub Package Registry VS GitHub Container Registry: Which to Use?

— Using GitHub Actions to Create Docker Images and Publish to GCR

— How to Make the GCR Docker Images Public

— How to Pull Public GCR Docker Images with Kubernetes

— How to Pull Private GCR Docker Images with Kubernetes


Image for post

Why use GitHub’s Container Registry instead of Docker Hub?

First of all, if you are using GitHub with your Docker project then using GitHub’s Container Registry simplifies your workflow by using only one service. Secondly, building Docker images using a GitHub Action is customizable, giving you more flexibility when building the Docker image and more importantly, more ways to debug issues when there is an error. Next, GitHub Actions will build and publish the Docker images in minutes, I often have to wait 20+ minutes for my new Docker image to be built and available on Docker Hub. Finally, GitHub currently has no plan to delete older Docker images unlike what Docker Hub recently announced.

GitHub Package Registry VS GitHub Container Registry: Which to Use?

In 2019 GitHub introduced the GitHub Package Registry then in 2020 they introduced the GitHub Container Registry. At first glance, both of those services look identical, but there is at least one important difference.

GitHub lists the key differences of the Container Registry as:

  • Store container images within your organization and user account, rather than a repository.
  • Set fine-grained permissions and visibility independent of repository permissions and visibility.
  • Access public container images anonymously.

However, in my opinion, the most important difference between the GitHub Package Registry and the GitHub Container Registry is images uploaded to the GitHub Package Registry cannot be deleted! Well, this isn’t 100% correct, if you make the GitHub repository private then you can delete the package, but making a GitHub repository private has unintended consequences.


Using GitHub Actions to Automatically Create Docker Images and Publish them to GitHub’s Container Registry

In this example I will be use the work I did to migrate my twitter-stream-archive Docker image from Docker Hub to GitHub’s Container Registry for my Kubernetes cluster. It doesn’t matter what twitter-stream-archive does, what is important is that twitter-stream-archive has a DockerFile in the GitHub repository root and will create a valid Docker image by running docker build . . The following instructions will not create a working Docker image without a working DockerFile in the GitHub repository.

If you want view the files and GitHub Actions yourself, the twitter-stream-archive GitHub repository is at: https://github.com/kevincoakley/twitter-stream-archive and the Docker images are at https://github.com/kevincoakley?tab=packages

#kubernetes #github #docker #developer

Build & Ship: GitHub Container Registry & Kubernetes
1.95 GEEK