How to login to Docker registries using Github Actions

雨燕双飞 提交于 2020-08-22 11:55:41

问题


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

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?


回答1:


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.

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

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

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

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

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




回答2:


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

Try this action instead as actions/docker/login@master appears to have been deprecated.




回答3:


I found Git hub action: 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.




回答4:


For logging in to dockerhub you can use the action provided in the actions/docker repo.

Which looks like this:

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


来源:https://stackoverflow.com/questions/58226756/how-to-login-to-docker-registries-using-github-actions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!