我们经常发布文档更新,此页面的翻译可能仍在进行中。有关最新信息,请访问英文文档。如果此页面上的翻译有问题,请告诉我们

Configuring Docker for use with GitHub Packages

您可以配置 Docker 客户端以使用 GitHub 包注册表 发布和检索 docker 镜像。

GitHub 包注册表 is available with GitHub Free, GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub One. GitHub 包注册表 不适用于使用旧版每仓库计划的公共或私有仓库。 更多信息请参阅“GitHub 的产品”。

本文内容

向 GitHub 包注册表 验证

您需要访问令牌才能发布、安装和删除 GitHub 包注册表 中的包。 您可以使用个人访问令牌直接向 GitHub 包注册表 或 GitHub API 验证您的用户名。 您可以使用 GITHUB_TOKEN 以通过 GitHub 操作 工作流程进行身份验证。

Authenticating with a personal access token

您必须使用具有适当范围的个人访问令牌才可在 GitHub 包注册表 中发布和安装。 更多信息请参阅“关于 GitHub 包注册表”。

You can authenticate to GitHub 包注册表 with Docker using the docker command. Replace USERNAME with the name of your user account on GitHub and TOKEN with your personal access token.

$ docker login -u USERNAME -p TOKEN docker.pkg.github.com

Authenticating with the GITHUB_TOKEN

如果您使用的是 GitHub 操作 工作流程,可以使用 GITHUB_TOKEN 发布和使用 GitHub 包注册表 中的软件包,而无需存储和管理个人访问令牌。 更多信息请参阅“使用 GITHUB_TOKEN 验证身份”。

发布包

GitHub 包注册表 支持每个仓库的多个顶层 Docker 镜像。 A repository can have any number of image tags. You may experience degraded service publishing or installing Docker images larger than 10GB, layers are capped at 5GB each. For more information, see "Docker tag" in the Docker documentation.

由于不支持大写字母,因此,即使您的 GitHub 用户或组织名称中包含大写字母,也必须对仓库所有者使用小写字母。

在发布包后,您可以在 GitHub 上查看该包。 更多信息请参阅“查看包”。

  1. Determine the image name and ID for your docker image using docker images.

    $ docker images
    > < >
    > REPOSITORY        TAG        IMAGE ID       CREATED      SIZE
    > IMAGE_NAME        VERSION    IMAGE_ID       4 weeks ago  1.11MB
  2. Using the Docker image ID, tag the docker image, replacing OWNER with the name of the user or organization account that owns the repository, REPOSITORY with the name of the repository containing your project, IMAGE_NAME with name of the package or image, and VERSION with package version at build time.

    $ docker tag IMAGE_ID docker.pkg.github.com/OWNER/REPOSITORY/IMAGE_NAME:VERSION
  3. If you haven't already built a docker image for the package, build the image, replacing OWNER with the name of the user or organization account that owns the repository, REPOSITORY with the name of the repository containing your project, IMAGE_NAME with name of the package or image, VERSION with package version at build time, and PATH to the image if it isn't in the current working directory.

    $ docker build -t docker.pkg.github.com/OWNER/REPOSITORY/IMAGE_NAME:VERSION PATH
  4. Publish the image to GitHub 包注册表.

    $ docker push docker.pkg.github.com/OWNER/REPOSITORY/IMAGE_NAME:VERSION

    Note: You must push your image using IMAGE_NAME:VERSION and not using IMAGE_NAME:SHA.

Example publishing a Docker image

You can publish version 1.0 of the monalisa image to the octocat/octo-app repository using an image ID.

$ docker images

> REPOSITORY           TAG      IMAGE ID      CREATED      SIZE
> monalisa             1.0      c75bebcdd211  4 weeks ago  1.11MB

# Tag the image with OWNER/REPO/IMAGE_NAME
$ docker tag c75bebcdd211 docker.pkg.github.com/octocat/octo-app/monalisa:1.0

# Push the image to GitHub 包注册表
$ docker push docker.pkg.github.com/octocat/octo-app/monalisa:1.0

You can publish a new Docker image for the first time and name it monalisa.

# Build the image with docker.pkg.github.com/OWNER/REPOSITORY/IMAGE_NAME:VERSION
# Assumes Dockerfile resides in the current working directory (.)
$ docker build -t docker.pkg.github.com/octocat/octo-app/monalisa:1.0 .

# Push the image to GitHub 包注册表
$ docker push docker.pkg.github.com/octocat/octo-app/monalisa:1.0

安装包

You can use the docker pull command to install a docker image from GitHub 包注册表, replacing OWNER with the name of the user or organization account that owns the repository, REPOSITORY with the name of the repository containing your project, IMAGE_NAME with name of the package or image, TAG_NAME with tag for the image you want to install. 由于不支持大写字母,因此,即使您的 GitHub 用户或组织名称中包含大写字母,也必须对仓库所有者使用小写字母。

$ docker pull docker.pkg.github.com/OWNER/REPOSITORY/IMAGE_NAME:TAG_NAME

Note: You must pull the image using IMAGE_NAME:VERSION and not using IMAGE_NAME:SHA.

延伸阅读

问问别人

找不到要找的内容?

联系我们