How to Push docker image to Github Container Registry?

How to Push docker image to Github Container Registry?

To access GitHub container registry you need to create Personal Access Token (PAT) on GitHub:

  • Go to "Personal Access Token" settings page -> github.com/settings/tokens
  • Click "Generate new token"
  • Choose appropriate token expiration duration.
  • Choose read, write packages permission, Since we want to push(write) and pull(read) docker images.
  • Click "Generate token" and copy the token

New_personal_access_token.png

Login into Github Container Registry

Login into Github Container Registry with your username and the personal access token we got in the previous step.

docker login ghcr.io -u GITHUB_USERNAME

Build Docker image and Tag the image

# cd into you dockerized project
docker build -t IMAGE_NAME:VERSION  . 

# re-tag the image with ghcr path
docker tag IMAGE_NAME:VERSION ghcr.io/GITHUB_USERNAME_OR_ORG_NAME/IMAGE_NAME:VERSION

Push to Github Container Registry

docker push ghcr.io/GITHUB_USERNAME_OR_ORG_NAME/IMAGE_NAME:VERSION