英文:
Docker Build Failed in Github Actions - failed to read dockerfile
问题
我有以下的目录结构:
├── .github/workflows
│ ├── deploy.yml
├── app
│ ├── Dockerfile
│ ├── __init__.py
│ ├── main.py
│ ├── requirements.txt
在deploy.yml
中,我有以下内容:
name: TestJobs
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build and push
uses: docker/build-push-action@v2
with:
context: ./app # 甚至尝试过只使用 "app" 而不使用双引号
file: ./Dockerfile # 甚至尝试过只使用 "Dockerfile" 而不使用双引号
tags: myimage:latest
outputs: type=docker,dest=/tmp/myimage.tar
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: myimage
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
更改为以下内容,一切都能正常工作
. . .
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
. . .
有人能帮我找到这个相对路径的问题吗?
英文:
I have the following Directory structure:
├── .github/workflows
│ ├── deploy.yml
├── app
│ ├── Dockerfile
│ ├── __init__.py
│ ├── main.py
│ ├── requirements.txt
And in the deploy.yml
I have the following content:
name: TestJobs
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build and push
uses: docker/build-push-action@v2
with:
context: ./app # even tried with just "app" without double quotation
file: ./Dockerfile # even tried with just "Dockerfile" without double quotation
tags: myimage:latest
outputs: type=docker,dest=/tmp/myimage.tar
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: myimage
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
. . .
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
. . .
Can someone help me find the issue with this relative-path here?
答案1
得分: 1
这是我的构建步骤:
- name: 构建并推送 Docker 镜像
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
或者
- name: 构建并推送 Docker 镜像
uses: docker/build-push-action@v4
with:
context: .
file: ./examples/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
在第一个示例中,我的 Docker 文件位于我的存储库的根目录。在第二个示例中,我的 Docker 文件位于一个名为 "example"(您的是 "app")的文件夹中。因此,使用以下方法对您来说应该有效:
- name: 构建并推送 Docker 镜像
uses: docker/build-push-action@v4
with:
context: .
file: ./app/Dockerfile
push: true
tags: myimage:latest
outputs: type=docker,dest=/tmp/myimage.tar
英文:
Here my build steps:
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
or
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
file: ./examples/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
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:
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
file: ./app/Dockerfile
push: true
tags: myimage:latest
outputs: type=docker,dest=/tmp/myimage.tar
答案2
得分: 0
上下文: app/
我认为这可能会起作用。
英文:
context: app/
I think that may do it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论