2.1.3 Deploy a Public Image to GitHub Container Registry
This tutorial will demonstrate how to (1) activate GitHub Container Registry from your local device, (2) push an image to GHCR and (3) make that image public.
Pre-Requisites
Registrations
Installations
Note: Run the following commands in Terminal/Command line to verify Installations
docker -v
git -v
Activate GitHub Container Registry
- Navigate to GitHub Personal Access Token Creation Form
- Set
Note
toGitHubContainerRegistry
- Set
Expiration
toNo expiration
-
Select the following Scopes
write:packages delete:packages
- Scroll Down and click
Generate Token
- Copy your Access Token
- Open Terminal
- Follow Mac Instructions or Windows Instructions to add GHCR Token to Environment variables
Add GHCR Token to Mac Environment Variables
- Run the following commands
-
Add Token to Temporary Environment Variables
export CR_PAT=<your-token>
-
Token as an Environment Variables permanently
Mac Instructions
Note: Depends on the type of shell you are running bash (.bash_profile) or zsh (.zshrc)
zsh bash echo "\nexport CR_PAT=$CR_PAT" >> ~/.zshrc
echo "\nexport CR_PAT=$CR_PAT" >> ~/.bash_profile
-
Quit and Reopen Terminal
-
Make sure this has been added to your Environment
echo $CR_PAT
-
Apply Token
echo $CR_PAT | docker login ghcr.io -u <your-username> --password-stdin
Note: Remove alligator clips
<
&>
-
Add GHCR Token to Windows Environment Variables
- Open Control Plane
- Click
System & Security
,System
,Advanced System Settings
,Environment Variables
- Under ‘System Variables’ Click
New
- Set Variable Name to
CR_PAT
- For Variable value paste the PAT from GitHub
- Press
OK
- Restart Command Prompt
- Run the following command to make sure this has been added to your Environment
set CR_PAT
- Apply Token
echo %CR_PAT% | docker login ghcr.io -u <your-username> --password-stdin
Note: Remove alligator clips
<
&>
Push Image to GitHub Container Registry
- Run the following commands
- Tag your Image locally
docker tag resume-image:latest ghcr.io/<github-username>/resume-image:latest
Note: Remove alligator clips
<
&>
- Test that your image was tagged sucessfully
docker image ls
Note: You should see a new image with the name
ghcr.io/<github-username>/resume-image:latest
- Push your image to GitHub Container Registry
docker push ghcr.io/<github-username>/resume-image:latest
Note: Remove alligator clips
<
&>
- Run the following command to test that your image successfully pushed
docker inspect ghcr.io/<github-username>/resume-image
Note: Remove alligator clips
<
&>
- Tag your Image locally
Make your Image Public
- Navigate to your GitHub Packages from your Github Profile
- Select your image
- On the right side click
Package Settings
- Scroll down to
Danger Zone
- Next to
Change package visibility
, ClickChange Visibility
- Select
Public
- Complete steps for confirmation
- Go back to your Packages
- Make sure the label
Private
is not on your image