简体   繁体   English

如何使用 Github 操作登录到 Docker 注册表

[英]How to login to Docker registries using Github Actions

Im trying to push a docker image to public docker repository using github actions following their documentation but I cant make it work:我尝试使用 github 操作按照他们的文档将 docker 图像推送到公共 docker 存储库,但我无法使其工作:

name: CI

on:
  push:
    branches:
      - master
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: actions/docker/login@master
        with: # Set the secret as an input
          DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
          DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
        env: # Set the secret in the env
          DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
          DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
      - name: Test
        run: mvn clean verify -U
      - name: build
        run: ./mvnw compile jib:dockerBuild
      - name: push
        run:  docker push odfsoft/guess-game:latest

I get the following error:我收到以下错误:

/usr/bin/docker run --name bb8146f4246c56a44203bb2667ccfbdcab81_f18969 --label 04bb81 --workdir /github/workspace --rm -e DOCKER_USERNAME -e DOCKER_PASSWORD -e INPUT_DOCKER_USERNAME -e INPUT_DOCKER_PASSWORD -e HOME -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e RUNNER_OS -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/spring-boot-guess-game/spring-boot-guess-game":"/github/workspace" 04bb81:46f4246c56a44203bb2667ccfbdcab81
Error: Cannot perform an interactive login from a non TTY device

is this something related to my action or a limitation in github actions?这是否与我的操作或 github 操作的限制有关?

The actions/docker action has now been deprecated. actions/docker操作现已弃用。 If you visit the repository you will see that the repository is archived and has the following message.如果您访问存储库,您将看到该存储库已归档并具有以下消息。

This action is deprecated in favor of using the run script step in the new YAML language to run the docker cli.不推荐使用此操作,而是使用新 YAML 语言中的运行脚本步骤来运行 docker cli。

https://github.com/actions/docker https://github.com/actions/docker

So the recommended way to login to Docker registries is to use the run script command as follows.因此登录 Docker 注册表的推荐方法是使用run脚本命令,如下所示。

For the public DockerHub registry:对于公共 DockerHub 注册表:

name: my workflow
on:
  push:
    branches:
      - master
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - name: Login to DockerHub Registry
        run: echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin

For a private registry, such as the new GitHub Package Registry, you also need to specify the hostname:对于私有注册表,例如新的 GitHub Package Registry,还需要指定主机名:

name: my workflow
on:
  push:
    branches:
      - master
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - name: Login to GitHub Package Registry
        run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login docker.pkg.github.com -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin

Also see this answer for complete workflow examples of docker image publishing.另请参阅此答案以获取 docker 图像发布的完整工作流程示例。

https://github.com/marketplace/actions/docker-login https://github.com/marketplace/actions/docker-login

Try this action instead as actions/docker/login@master appears to have been deprecated.请尝试此操作,因为actions/docker/login@master似乎已被弃用。

I found Git hub action: Build and push Docker images我发现 Git 集线器操作:构建并推送 Docker 图像

https://github.com/marketplace/actions/build-and-push-docker-images https://github.com/marketplace/actions/build-and-push-docker-images

It works well, I was able to build and push docker image to Docker Hub.它运行良好,我能够构建 docker 映像并将其推送到 Docker 集线器。

For logging in to dockerhub you can use the action provided in the actions/docker repo .要登录 dockerhub,您可以使用actions/docker repo中提供的操作。

Which looks like this:看起来像这样:

action "Docker Login" {
  uses = "actions/docker/login@master"
  secrets = ["DOCKER_USERNAME", "DOCKER_PASSWORD"]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM