GitHub Packages and Container Registry
GitHub packages use the container registry ghcr.io to store and manage Docker images. The Container Registry stores all the images within the organization or your personal account and also associate the image to your repository. In this article we will look at how to use GitHub Packages as Container Registry with a Docker Build and Push example.
First step is to use the personal access token (PAT) to authenticate to the Container Registry ghcr.io.
I am using a linux VM running Ubuntu.
1. Save the PAT as an environment variable
$ export CR_PAT=ENTER_YOUR_TOKEN
2. Login to the container registry using the command
echo $CR_PAT | docker login ghcr.io -u USERNAME — password-stdin
3. Sample Dockerfile to create an image
4. Build the Docker image from the Dockerfile
$ docker build -t hello_docker .
5. Tag the image
$ docker tag 75610137a1c9 ghcr.io/package-org/docker-registry/hello-world:latest
Here package-org is the name of my GitHub Organization and docker-registry is the repository.
6. Push the image to GitHub Packages Container Registry
$ docker push ghcr.io/package-org/docker-registry/hello-world:latest
7. To view the docker image in the container registry, go to the GitHub ORG → Repo and Packages section on the right below.
8. Make image Public
By default the image is Private and accessible to the members of the repo. To make the image public to have everyone access it click on the image → Package settings
Scroll down to the Danger Zone and Click on Change Visibility to public.
Note: If the image is made public there is no way to make it Private again.
To summarise we have seen the feature of GitHub Packages and how to use it as Container Registry to store Docker images.
Thank you for reading.