Contents

Github Container Registry

Containerize all the things and store them in GitHub Container Registry

Account Preparation

  1. Create a Repo here

  2. 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

  3. 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
    
  4. 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

  1. Write your Docekrfile

  2. Building container images

    1
    
    docker build -t hello_docker .
    
  3. Tagging container images

    1. 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
      
    2. 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
      
    3. Pushing container images

      1
      
      docker push ghcr.io/OWNER/IMAGE_NAME:latest
      

Attached Packages to a Repo

  1. Write your Docekrfile
This is a tip

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"

  1. Building container images

    1
    
    docker build -t ghcr.io/OWNER/REPO_NAME/IMAGE_NAME:latest .
    
  2. Tagging container images

    1. 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
      
    2. 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
      
    3. Pushing container images

      1
      
      docker push ghcr.io/OWNER/IMAGE_NAME:latest
      

Security

  1. Access to this package can be managed via the packages' settings
    1. It can be inherited from the repo’s ACL or it can be specified separately
  2. Private repos need to invite users in order to view containers.