Push Docker images from GitHub Actions to GitHub Container Registry

Pushing with the GitHub Container Registry itself and commands is explained in detail in Procedures for pushing Docker images to GitHub Container Registry (ghcr.io). Please have a look there.

procedure

Overview

Instructions for pushing a Docker image from GitHub Actions to Docker Hub can be found on GitHub Docs (Procedure Documentation (https://docs.github.com/ja/actions/language-and-framework-guides/publishing-docker-images) )). This time, just use it and point the push destination to the GitHub Container Registry (ghcr.io).

Setting login information for GitHub Container Registry (ghcr.io)

Create a Personal Access Token (PAT) from your GitHub account settings (Procedure Documents (https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-) token)). Check read: packages and write: packages as permissions. Save the created PAT in the GitHub repository as an encrypted secret (Procedure Documentation (https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing) -encrypted-secrets # creating-encrypted-secrets-for-a-repository)). Here, save it with the key CR_PAT.

Creating workflows (GitHub Actions)

Publish images to GitHub Packages Create a workflow by referring to the document. The point to change is --Replace GitHub Packages with GitHub Container Registry --Replace docker.pkg.github.com with ghcr.io --Replace $ {{secrets.GITHUB_TOKEN}} with $ {{secrets.CR_PAT}} --Change the value of repository: to $ {{github.repository}}

Below is the workflow for pushing to GitHub Container Registry (ghcr.io).

yaml:.github/workflows/docker-publish.yml


name: Publish Docker image
on:
  release:
    types: [published]
jobs:
  push_to_registry:
    name: Push Docker image to GitHub Container Registry
    runs-on: ubuntu-latest
    steps:
      - name: Check out the repo
        uses: actions/checkout@v2
      - name: Push to GitHub Container Registry
        uses: docker/build-push-action@v1
        with:
          username: ${{ github.actor }}
          password: ${{ secrets.CR_PAT }}
          registry: ghcr.io
          repository: ${{ github.repository }}
          tag_with_ref: true
        env:
          DOCKER_BUILDKIT: 1

Verification

The workflow example above is triggered by publishing a GitHub release, so publish and validate it. The content of the verification is also described in Procedure for pushing Docker image to GitHub Container Registry (ghcr.io), so please refer to that.

Summary

I've omitted a lot of explanations about GitHub Container Registry (ghcr.io), but I introduced the workflow to push to GitHub Container Registry (ghcr.io) with GitHub Actions. It's very easy to do, so please take advantage of it.

Recommended Posts

Push Docker images from GitHub Actions to GitHub Container Registry
Steps to push Docker image to GitHub Container Registry (ghcr.io)
Test, build, and push your Docker image to GitHub Container Registry using GitHub Actions
Migrate Dockerhub images to Github Container Registry
How to push from Tarminal to GitHub
The story of pushing a Docker container to GitHub Package Registry and Docker Hub with GitHub Actions
[Docker] Copy files from docker container to host
[GCP] Until you push the local Docker image to the Container Registry
How to get a heapdump from a Docker container
Setting to exit from Docker container with VScode
Copy files from docker container to host (docker cp)
Migrating from vargrant to docker
Until you push to Github
GitHub Actions Introduction to self-made actions
Getting Started with GitHub Container Registry instead of Docker Hub
[Docker] How to access the host from inside the container. http://host.docker.internal:
Introduction to Linux Container / Docker (Part 1)
Introduction to Linux Container / Docker (Part 2)
Addicted to project imports from GitHub
Pass environment variables to docker container
[Docker] Operation up to container creation # 2
Update MySQL from 5.7 to 8.0 with Docker
Push the Docker Image distributed by Docker Hub to Google Container Registry and start the VM based on that Image
Publish Docker Image on GitHub Package Registry
One liner to delete all Docker images
Until Docker beginners create Docker images from Dockerfile
Investigate the replacement from Docker to Podman.
Docker container build fails to install php-radis
Introduction to Docker / Kubernetes Practical Container Development
Error response from daemon: conflict: Conflict when trying to create Docker container, so solution
I was addicted to not being able to connect to AWS-S3 from the Docker container
How to check the logs in the Docker container
POST images from Android to PHP using Retrofit
Access docker registry from client PC via http
I made a Docker container to run Maven
How to update pre-built files in docker container
Push the image to docker hub using Jib
Temporarily move Docker environment from Mac to AWS
Docker for Windows: MySQL container does not start when migrating from Hyper-v to WSL2