Steps to push Docker image to GitHub Container Registry (ghcr.io)

Overview

On September 1, 2020, GitHub announced GitHub Container Registry as a public beta and started using it from the same day. became. It's one of the public registries (where you put your Docker images) like Docker Hub, and it's a service that anyone with a GitHub account can use.

This summarizes the steps to push a Docker image on ghcr.io and make the image available for anyone to download.

What is GitHub Container Registry?

--A registry of (currently) free, unlimited-capacity Docker images provided by GitHub (ghcr.io is separate from the previous docker.pkg.github.com) --Docker images can be downloaded by anyone (anonymous pulls), and you can choose public or private. --You can't delete the GitHub Package image, but you can delete the Docker image published on ghcr.io. --To use it, use the docker login command to log in to ghcr.io. Use GitHub's Personal Token for login authentication

From the above, GitHub Container Registry makes Docker images to third parties without being restricted or affected by Docker Hub's new image storage policy. It can be said that it is a place that can be published (at the moment).

procedure

To push and publish an image to ghcr.io

To send the image to GitHub Container Registry (GHCR), you need to log in to GHCR with the docker login command in advance. In order to log in, you need to create a Personal Access Token on your settings page on GitHub (Procedure Documentation (https://docs.github.com/en/github/authenticating-to-) github / creating-a-personal-access-token)).

Here, it is assumed that the character string of Personal Access Token is recorded in ~ / ghcr.txt.

Then access GHCR with the docker login command. Below <github username> is your own username.

cat ~/ghcr.txt | docker login ghcr.io -u <github username> --password-stdin

If the authentication is successful, you will see a message similar to the following:

WARNING! Your password will be stored unencrypted in /home/name/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

To submit an image, you must tag the image before submitting it. For Docker Hub it was in the format <username> / imagename: tag, but for GHCR it should be ghcr.io/ <username> / imagename: tag.

For example

--Image of image ID bf9f52b2d3fa

If there is this

--Repository name docker-sample-nginx --Name the image sample-nginx --Tag latest

If you want something like this, you need to tag the image you send with ghcr.io/zembutsu/docker-sample-nginx/sample-nginx:latest. To do this, use the docker tag command and run:

docker tag bf9f52b2d3fa ghcr.io/zembutsu/docker-sample-nginx/sample-nginx:latest

After confirming the tag addition with docker images, just send it with the docker push command.

$ docker push ghcr.io/zembutsu/docker-sample-nginx/sample-nginx:latest
The push refers to repository [ghcr.io/zembutsu/docker-sample-nginx/sample-nginx]
a49a33440fe7: Pushed
c63ea97607b8: Pushed
6ad8d562c843: Layer already exists
425ee8569962: Layer already exists
5d9ee84be1ec: Layer already exists
6bcd003260b2: Layer already exists
50644c29ef5a: Layer already exists
latest: digest: sha256:d6f2938d0fab3daeb6433c361da460970eb9b8d2796f1679afe6e41bb87b1937 size: 1774

At this point, a private repository with the name docker-sample-nginx is automatically created, and anyone who knows the image path (image name / tag) can download it.

To see the uploaded image, click the Packages tab from your GitHub profile and you'll see the Docker image information marked Private in the package information.

image.png

By clicking the package name displayed here, you can check the URL to download (pull) the image, publish the image, or delete the image. Click Edit package to change these states.

image.png

You can view all tags with View All versions and choose to delete each tag.

image.png

Also, Package settings gives you the option of Make public or Delete this package.

image.png

If you select Make public here, the package information about the target image will also be displayed on your profile.

Enjoy!

Reference information

Recommended Posts

Steps to push Docker image to GitHub Container Registry (ghcr.io)
Docker push to GitHub Container Registry (ghcr.io)
Minimal Workflow to push Docker image to Github Container Registry with Github Actions
Push Docker images from GitHub Actions to GitHub Container Registry
Test, build, and push your Docker image to GitHub Container Registry using GitHub Actions
[GCP] Until you push the local Docker image to the Container Registry
[Personal notes] How to push a Docker image to GitHub Packages
Publish Docker Image on GitHub Package Registry
Migrate Dockerhub images to Github Container Registry
Push the image to docker hub using Jib
Push the Docker Image distributed by Docker Hub to Google Container Registry and start the VM based on that Image
Until you push to Github
Getting Started with GitHub Container Registry instead of Docker Hub
The story of pushing a Docker container to GitHub Package Registry and Docker Hub with GitHub Actions
Introduction to Linux Container / Docker (Part 1)
How to push from Tarminal to GitHub
Steps to run docker on Mac
Migrate Docker image to another server
Introduction to Linux Container / Docker (Part 2)
2. Create Docker image and register Registry
Pass environment variables to docker container
[Docker] Operation up to container creation # 2
[Docker] Copy files from docker container to host
[Docker] Start container, start bash in container, delete image
Docker container build fails to install php-radis
Introduction to Docker / Kubernetes Practical Container Development
Steps to register Java files on GitHub
I tried to verify AdoptOpenJDK 11 (11.0.2) with Docker image
How to check the logs in the Docker container
How to get a heapdump from a Docker container
How to make Spring Boot Docker Image smaller
Setting to exit from Docker container with VScode
Copy files from docker container to host (docker cp)
I made a Docker container to run Maven
How to update pre-built files in docker container
How to give your image to someone with docker
Update container image with KUSANAGI Runs on Docker
Change the location folder of Docker image & container