Docker Build Failed in Github Actions – failed to read dockerfile

huangapple go评论110阅读模式
英文:

Docker Build Failed in Github Actions - failed to read dockerfile

问题

我有以下的目录结构:

  1. ├── .github/workflows
  2. ├── deploy.yml
  3. ├── app
  4. ├── Dockerfile
  5. ├── __init__.py
  6. ├── main.py
  7. ├── requirements.txt

deploy.yml中,我有以下内容:

  1. name: TestJobs
  2. on: [push]
  3. jobs:
  4. build:
  5. runs-on: ubuntu-latest
  6. steps:
  7. - name: Checkout
  8. uses: actions/checkout@v2
  9. - name: Set up Docker Buildx
  10. uses: docker/setup-buildx-action@v1
  11. - name: Build and push
  12. uses: docker/build-push-action@v2
  13. with:
  14. context: ./app # 甚至尝试过只使用 "app" 而不使用双引号
  15. file: ./Dockerfile # 甚至尝试过只使用 "Dockerfile" 而不使用双引号
  16. tags: myimage:latest
  17. outputs: type=docker,dest=/tmp/myimage.tar
  18. - name: Upload artifact
  19. uses: actions/upload-artifact@v2
  20. with:
  21. name: myimage
  22. path: /tmp/myimage.tar

但是,它失败并显示以下错误

> ERROR: failed to solve: failed to read dockerfile: open /tmp/buildkit-mount2199217382/Dockerfile: no such file or directory
Error: buildx failed with: ERROR: failed to solve: failed to read dockerfile: open /tmp/buildkit-mount2199217382/Dockerfile: no such file or directory

注意:如果我将所有内容移动到app/内并将deploy.yml更改为以下内容,一切都能正常工作

  1. . . .
  2. - name: Build and push
  3. uses: docker/build-push-action@v2
  4. with:
  5. context: .
  6. file: ./Dockerfile
  7. . . .

有人能帮我找到这个相对路径的问题吗?

英文:

I have the following Directory structure:

  1. ├── .github/workflows
  2. ├── deploy.yml
  3. ├── app
  4. ├── Dockerfile
  5. ├── __init__.py
  6. ├── main.py
  7. ├── requirements.txt

And in the deploy.yml I have the following content:

  1. name: TestJobs
  2. on: [push]
  3. jobs:
  4. build:
  5. runs-on: ubuntu-latest
  6. steps:
  7. - name: Checkout
  8. uses: actions/checkout@v2
  9. - name: Set up Docker Buildx
  10. uses: docker/setup-buildx-action@v1
  11. - name: Build and push
  12. uses: docker/build-push-action@v2
  13. with:
  14. context: ./app # even tried with just "app" without double quotation
  15. file: ./Dockerfile # even tried with just "Dockerfile" without double quotation
  16. tags: myimage:latest
  17. outputs: type=docker,dest=/tmp/myimage.tar
  18. - name: Upload artifact
  19. uses: actions/upload-artifact@v2
  20. with:
  21. name: myimage
  22. path: /tmp/myimage.tar

But. it fails with the following error

> ERROR: failed to solve: failed to read dockerfile: open /tmp/buildkit-mount2199217382/Dockerfile: no such file or directory
Error: buildx failed with: ERROR: failed to solve: failed to read dockerfile: open /tmp/buildkit-mount2199217382/Dockerfile: no such file or directory

Note: Evrything works fine if I moved all the content inside the app/ to the root directory and change the deploy.yml as below

  1. . . .
  2. - name: Build and push
  3. uses: docker/build-push-action@v2
  4. with:
  5. context: .
  6. file: ./Dockerfile
  7. . . .

Can someone help me find the issue with this relative-path here?

答案1

得分: 1

这是我的构建步骤:

  1. - name: 构建并推送 Docker 镜像
  2. uses: docker/build-push-action@v4
  3. with:
  4. context: .
  5. push: true
  6. tags: ${{ steps.meta.outputs.tags }}
  7. labels: ${{ steps.meta.outputs.labels }}

或者

  1. - name: 构建并推送 Docker 镜像
  2. uses: docker/build-push-action@v4
  3. with:
  4. context: .
  5. file: ./examples/Dockerfile
  6. push: true
  7. tags: ${{ steps.meta.outputs.tags }}
  8. labels: ${{ steps.meta.outputs.labels }}

在第一个示例中,我的 Docker 文件位于我的存储库的根目录。在第二个示例中,我的 Docker 文件位于一个名为 "example"(您的是 "app")的文件夹中。因此,使用以下方法对您来说应该有效:

  1. - name: 构建并推送 Docker 镜像
  2. uses: docker/build-push-action@v4
  3. with:
  4. context: .
  5. file: ./app/Dockerfile
  6. push: true
  7. tags: myimage:latest
  8. outputs: type=docker,dest=/tmp/myimage.tar
英文:

Here my build steps:

  1. - name: Build and push Docker image
  2. uses: docker/build-push-action@v4
  3. with:
  4. context: .
  5. push: true
  6. tags: ${{ steps.meta.outputs.tags }}
  7. labels: ${{ steps.meta.outputs.labels }}

or

  1. - name: Build and push Docker image
  2. uses: docker/build-push-action@v4
  3. with:
  4. context: .
  5. file: ./examples/Dockerfile
  6. push: true
  7. tags: ${{ steps.meta.outputs.tags }}
  8. labels: ${{ steps.meta.outputs.labels }}

In example one my docker file is at the root of my repo. In the second example my docker file its in a folder (like you) named example (your is app).so with that approach the following should work for you:

  1. - name: Build and push Docker image
  2. uses: docker/build-push-action@v4
  3. with:
  4. context: .
  5. file: ./app/Dockerfile
  6. push: true
  7. tags: myimage:latest
  8. outputs: type=docker,dest=/tmp/myimage.tar

答案2

得分: 0

  1. 上下文: app/

我认为这可能会起作用。

英文:
  1. context: app/

I think that may do it.

huangapple
  • 本文由 发表于 2023年1月9日 06:59:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/75051895.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定