Github Container Registry
Containerize all the things and store them in GitHub Container Registry
Account Preparation
Create a Repo here
Create a new personal access token (PAT) with the appropriate scopes for the tasks you want to accomplish. If your organization requires SSO, you must enable SSO for your new token. create here
Save your PAT. I recommend saving your PAT as an environment variable usong the command
read
. This command will expect a user input, paste your token and press enter ( nothing will be saved to the terminal history ).1
read CR_PAT
Using the CLI for your container type, sign in to the Container registry service at ghcr.io.
1
echo $CR_PAT | docker login ghcr.io -u USERNAME --password-stdin
Push to Container registry
Attached Packages to Account
Write your Docekrfile
Building container images
1
docker build -t hello_docker .
Tagging container images
Find the ID for the Docker image you want to tag.
1 2 3 4 5
$ docker images > REPOSITORY TAG IMAGE ID CREATED SIZE > ghcr.io/my-org/hello_docker latest 38f737a91f39 47 hours ago 91.7MB > ghcr.io/my-username/hello_docker latest 38f737a91f39 47 hours ago 91.7MB > hello-world latest fce289e99eb9 16 months ago 1.84kB
Tag your Docker image using the image ID and your desired image name and hosting destination.
1
docker tag 38f737a91f39 ghcr.io/OWNER/NEW_IMAGE_NAME:latest
Pushing container images
1
docker push ghcr.io/OWNER/IMAGE_NAME:latest
Attached Packages to a Repo
- Write your Docekrfile
In order to attach a package to a specific repository add the following lable in your Dockerfile
LABEL org.opencontainers.image.source="https://github.com/OWNER/REPO_NAME"
Building container images
1
docker build -t ghcr.io/OWNER/REPO_NAME/IMAGE_NAME:latest .
Tagging container images
Find the ID for the Docker image you want to tag.
1 2 3 4 5
$ docker images > REPOSITORY TAG IMAGE ID CREATED SIZE > ghcr.io/my-org/hello_docker latest 38f737a91f39 47 hours ago 91.7MB > ghcr.io/my-username/hello_docker latest 38f737a91f39 47 hours ago 91.7MB > hello-world latest fce289e99eb9 16 months ago 1.84kB
Tag your Docker image using the image ID and your desired image name and hosting destination.
1
docker tag 38f737a91f39 ghcr.io/OWNER/NEW_IMAGE_NAME:latest
Pushing container images
1
docker push ghcr.io/OWNER/IMAGE_NAME:latest
Security
- Access to this package can be managed via the packages’ settings
- It can be inherited from the repo’s ACL or it can be specified separately
- Private repos need to invite users in order to view containers.