Search code examples
dockergithub-actions

Authorization failure at Docker login step in Github Actions


As the title says, the build fails at the login step with the "Error: Error response from daemon: Get "https://registry-1.docker.io/v2/": unauthorized: incorrect username or password" message. My config is almost identical to the example in Docker's official docs (https://docs.docker.com/ci-cd/github-actions/), so I doubt it's the config. I've triple checked the credentials, and they appear to be true. The builder seems to be able to access the credentials as well, as they are printed as ***, because they are secrets. I am also able to log in through terminal using these credentials, yet Github is not. Is there anything I am missing?

name: ci

on:
  push:
    branches: [ "main" ]
    # Publish semver tags as releases.
    tags: [ 'v*.*.*' ]

env:
  USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
  PASSWORD: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

jobs:
  build:
    environment: prod
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3
        
      - name: Login to Docker Hub
        uses: docker/login-action@v2
        with:
          username: $USERNAME
          password: $PASSWORD

...Rest of the  yml

Solution

  • Documentation: https://docs.github.com/en/actions/learn-github-actions/environment-variables#using-contexts-to-access-environment-variable-values

    Environment variables are only resolved the way you've specified when they are used in commands.

    You have to change the two lines where you pass the credentials like this:

          - name: Login to Docker Hub
            uses: docker/login-action@v2
            with:
              username: ${{ env.USERNAME }}
              password: ${{ env.PASSWORD }}