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