Junius L
Junius L

Reputation: 16142

Docker build failing with no such file or directory

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

Upvotes: 3

Views: 3597

Answers (1)

Mushfikunnabi Nijhum
Mushfikunnabi Nijhum

Reputation: 71

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

Upvotes: 3

Related Questions