Publicamos atualizações frequentes em nossa documentação, e a tradução desta página ainda pode estar em andamento. Para obter as informações mais recentes, acesse a documentação em inglês. Se houver problemas com a tradução desta página, entre em contato conosco.

Configuring Docker for use with GitHub Packages

Você pode configurar o cliente do Docker para usar o GitHub Package Registry para publicar e recuperar imagens do Docker.

GitHub Package Registry is available with GitHub Free, GitHub Pro, GitHub Free for organizations, GitHub Team, GitHub Enterprise Cloud, and GitHub One. GitHub Package Registry is not available for private repositories owned by accounts using legacy per-repository plans. For more information, see "GitHub's products."

Neste artigo

Note: When installing or publishing a docker image, GitHub Package Registry does not currently support foreign layers, such as Windows images.

Autenticar-se no GitHub Package Registry

You need an access token to publish, install, and delete packages in GitHub Package Registry. You can use a personal access token to authenticate with your username directly to GitHub Package Registry or the GitHub API. You can use a GITHUB_TOKEN to authenticate using a GitHub Actions workflow.

Authenticating with a personal access token

You must use a personal access token with the appropriate scopes to publish and install packages in GitHub Package Registry. For more information, see "About GitHub Package Registry."

You can authenticate to GitHub Package Registry 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.

$ cat ~/TOKEN.txt | docker login https://docker.pkg.github.com -u USERNAME --password-stdin

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

For more information, see "Docker login."

Authenticating with the GITHUB_TOKEN

If you are using a GitHub Actions workflow, you can use a GITHUB_TOKEN to publish and consume packages in GitHub Package Registry without needing to store and manage a personal access token. For more information, see "Authenticating with the GITHUB_TOKEN."

Publicar um pacote

O GitHub Package Registry aceita várias imagens do Docker de nível superior por repositório. 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.

Como não é permitido usar letras maiúsculas, é preciso usar letras minúsculas no nome do proprietário do repositório, mesmo que o nome do usuário ou da organização no GitHub contenha letras maiúsculas.

After you publish a package, you can view the package on GitHub. For more information, see "Viewing packages."

  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 Package Registry.

    $ 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 Package Registry
$ 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 .

# Faça push da imagem no GitHub Package Registry
$ docker push docker.pkg.github.com/octocat/octo-app/monalisa:1.0

Instalar um pacote

You can use the docker pull command to install a docker image from GitHub Package Registry, 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. Como não é permitido usar letras maiúsculas, é preciso usar letras minúsculas no nome do proprietário do repositório, mesmo que o nome do usuário ou da organização no GitHub contenha letras maiúsculas.

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

Leia mais

Pergunte a uma pessoa

Não consegue encontrar o que procura?

Entrar em contato