12

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?

Folger Fonseca
  • 183
  • 1
  • 1
  • 11

6 Answers6

19

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.

peterevans
  • 34,297
  • 7
  • 84
  • 83
  • 5
    I got this error:: Error: Cannot perform an interactive login from a non TTY device – Sudip Bhandari Feb 29 '20 at 20:19
  • @SudipBhandari You get that error when you forget `` --password-stdin`` . ``echo "${{ secrets.DOCKER_PASSWORD }}" | docker login docker.pkg.github.com -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin`` – Alex 75 Feb 18 '22 at 21:31
4

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

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

bradj
  • 890
  • 5
  • 11
1

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.

shyam
  • 537
  • 6
  • 16
0

use docker/login-action@v1 to login to docker registry https://github.com/docker/login-action.

name: deploy
    
    on:
      push:
        branches:
          - main
    
    jobs:
      build:
        runs-on: ubuntu-latest
        steps:
          - uses: docker/login-action@v1
            with:
              registry: private-registry-url
              username: ${{ secrets.USERNAME  }}
              password: ${{ secrets.PASSWORD }}
Sukh N
  • 7
  • 1
0

For service containers, see this example:

jobs:
  build:
    container:
      image: octocat/ci-image:latest
      credentials:
        username: mona
        password: ${{ secrets.docker_hub_password}}
    services:
      db:
        image:  ghcr.io/octocat/testdb:latest
        credentials:
          username: ${{ github.repository_owner }}
          password: ${{ secrets.ghcr_password }}
Carter
  • 1,184
  • 11
  • 5
-5

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"]
}
schoash
  • 166
  • 1
  • 6
  • HCL has been deprecated in favor of yaml: https://help.github.com/en/articles/migrating-github-actions-from-hcl-syntax-to-yaml-syntax – bradj Oct 03 '19 at 21:38
  • yeah this was the example that I found earlier on but this does not work anymore because now you need to use yaml. btw I didnt down vote you. – Folger Fonseca Oct 04 '19 at 07:00