此版本的 GitHub Enterprise 将停止服务 2022-02-16. 即使针对重大安全问题,也不会发布补丁。 要获得更好的性能、改进的安全性和新功能,请升级到 GitHub Enterprise 的最新版本。 如需升级方面的帮助,请联系 GitHub Enterprise 支持

Working with the Docker registry

You can push and pull your Docker images using the GitHub Packages Docker registry, which uses the package namespace https://docker.pkg.github.com.

GitHub Packages 可用于 GitHub Free、GitHub Pro、组织的 GitHub Free、GitHub Team、GitHub Enterprise Cloud、GitHub Enterprise Server 和 GitHub AE。

注:这种包类型可能不适用于您的实例,因为站点管理员可以启用或禁用每种支持的包类型。 更多信息请参阅“为企业配置软件包支持”。

About Docker support

When installing or publishing a Docker image, the Docker registry does not currently support foreign layers, such as Windows images.

Authenticating to GitHub Packages

您需要访问令牌才能发布、安装和删除 GitHub Packages 中的包。

You can use a personal access token (PAT) to authenticate to GitHub Packages or the GitHub Enterprise Server API. 创建个人访问令牌时,可根据需要为令牌分配不同的作用域。 有关 PAT 与包相关的域的更多信息,请参阅“关于 GitHub Packages 的权限”。

要在 GitHub Actions 工作流程内向 GitHub Packages 注册表验证,您可以使用:

  • GITHUB_TOKEN 来发布与工作流程仓库相关联的包。
  • PAT 来安装与其他私有仓库(GITHUB_TOKEN 无法访问)相关联的包。

有关 GitHub Actions 工作流程中使用的 GITHUB_TOKEN 的更多信息,请参阅“工作流程中的身份验证”。

Authenticating with a personal access token

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

You can authenticate to GitHub Packages with Docker using the docker login command.

To keep your credentials secure, we recommend you save your personal access token in a local file on your computer and use Docker's --password-stdin flag, which reads your token from a local file.

If your instance has subdomain isolation enabled:

$ cat ~/TOKEN.txt | docker login docker.HOSTNAME -u USERNAME --password-stdin

If your instance has subdomain isolation disabled:

$ cat ~/TOKEN.txt | docker login HOSTNAME -u USERNAME --password-stdin

To use this example login command, replace USERNAME with your GitHub Enterprise Server username, HOSTNAME with the URL for your GitHub Enterprise Server instance, and ~/TOKEN.txt with the file path to your personal access token for GitHub Enterprise Server.

For more information, see "Docker login."

Publishing an image

Note: The GitHub Packages Docker registry will be superseded in a future GitHub Enterprise Server release with the Container registry, which offers improved container support.

Note: Image names must only use lowercase letters.

GitHub Packages supports multiple top-level Docker images per repository. 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 上查看该包。 更多信息请参阅“查看包”。

  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, HOSTNAME with the hostname of your GitHub Enterprise Server instance, and VERSION with package version at build time.

    If your instance has subdomain isolation enabled:

    $ docker tag IMAGE_ID docker.HOSTNAME/OWNER/REPOSITORY/IMAGE_NAME:VERSION

    If your instance has subdomain isolation disabled:

    $ docker tag IMAGE_ID HOSTNAME/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, HOSTNAME with the hostname of your GitHub Enterprise Server instance, and PATH to the image if it isn't in the current working directory.

    If your instance has subdomain isolation enabled:

    $ docker build -t docker.HOSTNAME/OWNER/REPOSITORY/IMAGE_NAME:VERSION PATH

    If your instance has subdomain isolation disabled:

    $ docker build -t HOSTNAME/OWNER/REPOSITORY/IMAGE_NAME:VERSION PATH
  4. Publish the image to GitHub Packages.

    If your instance has subdomain isolation enabled:

    $ docker push docker.HOSTNAME/OWNER/REPOSITORY/IMAGE_NAME:VERSION

    If your instance has subdomain isolation disabled:

    $ docker push HOSTNAME/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

These examples assume your instance has subdomain isolation enabled.

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.HOSTNAME/octocat/octo-app/monalisa:1.0

# Push the image to GitHub Packages
$ docker push docker.HOSTNAME/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.HOSTNAME/OWNER/REPOSITORY/IMAGE_NAME:VERSION
# Assumes Dockerfile resides in the current working directory (.)
$ docker build -t docker.HOSTNAME/octocat/octo-app/monalisa:1.0 .

# Push the image to GitHub Packages
$ docker push docker.HOSTNAME/octocat/octo-app/monalisa:1.0

Downloading an image

Note: The GitHub Packages Docker registry will be superseded in a future GitHub Enterprise Server release with the Container registry, which offers improved container support.

You can use the docker pull command to install a docker image from GitHub Packages, 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, HOSTNAME with the host name of your GitHub Enterprise Server instance, and TAG_NAME with tag for the image you want to install.

If your instance has subdomain isolation enabled:

$ docker pull docker.HOSTNAME/OWNER/REPOSITORY/IMAGE_NAME:TAG_NAME

If your instance has subdomain isolation disabled:

$ docker pull HOSTNAME/OWNER/REPOSITORY/IMAGE_NAME:TAG_NAME

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

Further reading

此文档对您有帮助吗?

隐私政策

帮助我们创建出色的文档!

所有 GitHub 文档都是开源的。看到错误或不清楚的内容了吗?提交拉取请求。

做出贡献

或者, 了解如何参与。