如何使用Github Actions登录Docker注册表 [英] How to login to Docker registries using Github Actions

查看:105
本文介绍了如何使用Github Actions登录Docker注册表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据其文档后的github操作将docker映像推送至公共docker存储库,但我无法使其工作:

Im trying to push a docker image to public docker repository using github actions following their documentation but I cant make it work:

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

我明白了降低错误:

/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

这与我的事情有关动作还是GitHub动作的限制?

is this something related to my action or a limitation in github actions?

推荐答案

actions / docker 现在已不建议使用该操作。如果您访问存储库,则会看到该存储库已存档,并显示以下消息。

The actions/docker action has now been deprecated. If you visit the repository you will see that the repository is archived and has the following message.


不建议使用此操作,而建议使用在新的YAML语言中运行脚本步骤以运行docker cli。

This action is deprecated in favor of using the run script step in the new YAML language to run the docker cli.

https://github.com/actions/docker

因此,建议的登录Docker注册表的方法是如下使用 run 脚本命令。

So the recommended way to login to Docker registries is to use the run script command as follows.

对于公共DockerHub注册表:

For the public DockerHub registry:

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

用于私人注册表,例如新的GitHub Package Registry,您还需要指定主机名:

For a private registry, such as the new GitHub Package Registry, you also need to specify the hostname:

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

另请参阅此答案以获取完整的工作流程示例docker图片发布。

Also see this answer for complete workflow examples of docker image publishing.

这篇关于如何使用Github Actions登录Docker注册表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆