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.
--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).
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.
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.
You can view all tags with View All versions
and choose to delete each tag.
Also, Package settings
gives you the option of Make public or Delete this package.
If you select Make public
here, the package information about the target image will also be displayed on your profile.
Enjoy!
Recommended Posts