2

I'm trying to build a docker image using Github actions and Docker build can't find the docker file.

When I run this

- name: Build the Docker image
  run: docker build . --file Dockerfile --build-arg NPM_TOKEN=${{ secrets.TOKEN }}  --tag my-image-name:$(date +%s)

It works, but when I change my Github workflow file to use the following format, it doesn't file the Dockerfile.

- name: Docker Build and Push
  uses: docker/build-push-action@v2
  with:
    context: .
    file: Dockerfile
    tags: my-image-name:t10
    build-args: |
      "NPM_TOKEN=${{ secrets.TOKEN }}"
    push: true

Error: buildx failed with: error: failed to solve: rpc error: code = Unknown desc = failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount4215207778/Dockerfile: no such file or directory

Directory structure

enter image description here

Junius L
  • 15,881
  • 6
  • 52
  • 96
  • 1
    You don't need to specify `file`, as you are using the default. But lets say you need to. According to the documentation, the default value of `file` is `/Dockerfile`. I'd try to put `./Dockerfile` in your case. Unfortunately I have no time right now to test this solution, so I'm just trying to point you in some direction – Maxim Krizhanovsky Aug 16 '22 at 14:53
  • I'm currently facing exactly the same issue, did you manage to resolve this? The main difference (that I could see at least) is that _docker/build-push-action@v2_ executes commands from **/usr/bin/docker -e {0}** whereas the manual approach _docker buildx build_ executes from **shell: /usr/bin/bash -e {0}** – Shaun May 09 '23 at 19:06

1 Answers1

2

You need to checkout first. Add the following lines first.

- name: Checkout
  uses: actions/checkout@v2

Also add ./ before Dockerfile

Final job description would be:

      - name: Checkout
        uses: actions/checkout@v2
      - name: Docker Build and Push
        uses: docker/build-push-action@v2
        with:
          context: .
          file: ./Dockerfile
          tags: my-image-name:t10
          build-args: |
              "NPM_TOKEN=${{ secrets.TOKEN }}"
          push: true