GitHub Container Registry と Docker パッケージレジストリとの主な違い
注釈: GitHub Container Registry は現在パブリックベータであり、変更されることがあります。 During the beta, storage and bandwidth are free. To use GitHub Container Registry, you must enable the feature preview. For more information, see "About GitHub Container Registry" and "Enabling improved container support."
GitHub Container Registry は既存の Packages Docker レジストリに取って代わるもので、コンテナ固有のニーズのいくつかをサポートできるよう最適化されています。
With the container registry you can:
- Store container images within your organization and user account, rather than a repository.
- Set fine-grained permissions and visibility independent of repository permissions and visibility.
- Access public container images anonymously.
詳しい情報については「GitHub Container Registryについて」を参照してください。
支払いの変更
During the GitHub Container Registry beta, both the new container registry and existing GitHub Packages Docker registry will be free. For more information about the GitHub Packages Docker registry, see "Configuring Docker for use with GitHub Packages."
After the beta, the same billing and storage rates that other GitHub Packages registries use will apply to the container registry. For more information, see "About billing for GitHub Packages."
ドメインの変更
container registry のドメインは ghcr.io
です。
レジストリ | URLの例 |
---|---|
GitHub Packages Docker レジストリ | docker.pkg.github.com/OWNER/REPOSITORY/IMAGE_NAME |
GitHub Container Registry | ghcr.io/OWNER/IMAGE_NAME |
コンテナレジストリで認証する
Note: Before you can use GitHub Container Registry, you must enable the feature for your account. For more information, see "Enabling improved container support."
container registry は、 ベース URL ghcr.io
で認証する必要があります。 container registry を使用するために、新しいアクセストークンの作成をお勧めします。
If you want to authenticate to
GitHub Container Registry in a GitHub Actions workflow, then you must use a personal access token (PAT). The GITHUB_TOKEN
does not currently have the required permissions. During the GitHub Container Registry beta, the only supported form of authentication is the PAT.
PATs can grant broad access to your account. We recommend selecting only the necessary read, write, or delete package
scope when creating a PAT to authenticate to the container registry. Avoid including the repo
scope in a PAT used by a GitHub Actions workflow because it gives unnecessary additional access.
If you'd like to use the container registry in actions during the beta, follow our security best practices for PAT use at "Security hardening for GitHub Actions."
-
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.
Note: If you select the
write:packages
scope, deselect therepo
scope when creating the PAT. Adding a PAT with therepo
scope as a secret in your repository allows the credential to be accessible to all collaborators in the repository. This gives unnecessary additional access when a PAT with therepo
scope is used within an action. For more information on security best practices for actions, see "Security hardening for GitHub Actions."- Select the
read:packages
scope to download container images and read their metadata. - Select the
write:packages
scope to download and upload container images and read and write their metadata. - Select the
delete:packages
scope to delete container images.
詳しい情報についてはコマンドラインのための個人のアクセストークンの作成を参照してください。
- Select the
-
Save your PAT. We recommend saving your PAT as an environment variable.
$ export CR_PAT=YOUR_TOKEN
-
Using the CLI for your container type, sign in to the GitHub Container Registry service at
ghcr.io
.$ echo $CR_PAT | docker login ghcr.io -u USERNAME --password-stdin > Login Succeeded
Docker CLI を使用して Docker イメージを移行する
GitHub Packages Docker レジストリでホストしている Docker イメージを移動するには、イメージを container registry に再公開する必要があります。 既存の Docker イメージを再公開するには、ローカルマシンでコマンドラインを使うことをお勧めします。
-
少なくとも
read:packages
スコープのある一時的な PAT (個人アクセストークン) を使用して、Docker レジストリにサインインします。 この PAT は、Docker レジストリにサインインしてイメージをプルダウンするためにのみ使用され、その後は削除して構いません。$ echo $READ_PACKAGES_TOKEN | docker login docker.pkg.github.com -u USERNAME --password-stdin
-
移行したいイメージをプルダウンします。OWNER はリポジトリを所有しているユーザまたは Organization アカウントの名前に、REPOSITORY はプロジェクトを含むリポジトリの名前に、IMAGE_NAME はパッケージまたはイメージの名前に、VERSION はインストールするイメージのタグにそれぞれ置き換えてください。 たとえば、
docker pull docker.pkg.github.com/octo-org/octoshift/octoshift:latest
は octo-org という Organization のoctoshift/octoshift
イメージの、最新のタグをプルします。$ docker pull docker.pkg.github.com/OWNER/REPOSITORY/IMAGE_NAME:VERSION
-
新しいドメインと新しいイメージ名でイメージにタグ付けし直します。 詳しい情報については、Dockerのドキュメンテーションの「Docker tag」を参照してください。 先ほどのステップで用いた URL と同じものを SOURCE URL とします。 TARGET_OWNER はコンテナイメージをの移行先であるユーザまたは Organization に、TARGET_IMAGE_NAME は新しい container registry イメージ名に置き換えます。
$ docker tag docker.pkg.github.com/SOURCE_OWNER/SOURCE_REPOSITORY/SOURCE_IMAGE_NAME:VERSION ghcr.io/TARGET_OWNER/TARGET_IMAGE_NAME:VERSION
-
新しい
container registry. read:packages
スコープと write:packages
スコープに限定した新しい PAT の作成をお勧めします。repo
スコープはもはや不要であり、以前の PAT は write:packages
スコープを持っていない場合があるからです。
$ echo $CR_PAT | docker login ghcr.io -u USERNAME --password-stdin
- タグ付けし直したイメージを container registry にプッシュします。
$ docker push ghcr.io/OWNER/IMAGE_NAME:VERSION
GitHub Actions ワークフローを更新する
Note: Before you can use GitHub Container Registry, you must enable the feature for your account. For more information, see "Enabling improved container support."
GitHub Packages Docker レジストリから Docker イメージを使用する GitHub Actions ワークフローがある場合、ワークフローを container registry に更新するといいでしょう。そうすればパブリックコンテナのイメージへの匿名アクセスが可能になり、きめ細かいアクセス権限を設定でき、コンテナに対するストレージと帯域幅が向上します。
-
ghcr.io
にある新しい container registry に Docker イメージを移行します。 例については、「Docker CLI を使用して Docker イメージを移行する」を参照してください。 -
GitHub Actions ワークフローファイルで、パッケージ URL を
https://docker.pkg.github.com
からghcr.io
に更新します。 -
Add your new container registry authentication personal access token (PAT) as a GitHub Actions secret. GitHub Container Registry は PAT において
GITHUB_TOKEN
の使用をサポートしていないので、CR_PAT
などの別のカスタム変数を使用する必要があります。 詳しい情報については「暗号化されたシークレットの作成と保存」を参照してください。 -
GitHub Actions ワークフローファイルにおいて、Docker レジストリ PAT (
${{ secrets.GITHUB_TOKEN }}
をコンテナレジストリ container registry PAT の新しい変数 (たとえば${{ secrets.CR_PAT }}
) に置き換えて、認証 PAT を更新します。
更新したワークフローの例
ワークフローの一部が Docker レジストリにホストされた Docker イメージにアクセスした場合は、次のようになります。
echo ${{ secrets.GITHUB_TOKEN }} | docker login https://docker.pkg.github.com -u $GITHUB_ACTOR --password-stdin
docker pull docker.pkg.github.com/github/octoshift/octoshift:latest
docker build . --tag docker.pkg.github.com/github/octoshift/octoshift:$GITHUB_SHA --cache-from docker.pkg.github.com/github/octoshift/octoshift:latest
docker push docker.pkg.github.com/github/octoshift/octoshift:$GITHUB_SHA
そして、ワークフローを新しい container registry URL と PAT で次のように更新する必要があります。
# new login with new container registry url and PAT
echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
# new container registry urls added
docker pull ghcr.io/github/octoshift:latest
docker build . --tag ghcr.io/github/octoshift:$GITHUB_SHA --cache-from ghcr.io/github/octoshift:latest
docker push ghcr.io/github/octoshift:$GITHUB_SHA