Python 无法为 COPY 创建 docker 映像失败:stat /var/lib/docker/tmp/docker-builder 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46907584/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can't create a docker image for COPY failed: stat /var/lib/docker/tmp/docker-builder error
提问by EdoBen
I want to create a docker image. This is my work directory: Dockerfile.in test.json test.py
我想创建一个泊坞窗图像。这是我的工作目录:Dockerfile.in test.json test.py
And this is my Dockerfile:
这是我的 Dockerfile:
COPY ./test.json /home/test.json
COPY ./test.py /home/test.py
RUN python test.py
When i launch this command:
docker build -f Dockerfile.in -t 637268723/test:1.0 .
当我启动此命令时:
docker build -f Dockerfile.in -t 637268723/test:1.0 .
It gives me this error:
它给了我这个错误:
`Step 1/5 : COPY ./test.json /home/test.json
---> Using cache
---> 6774cd225d60
Step 2/5 : COPY ./test.py /home/test.py
COPY failed: stat /var/lib/docker/tmp/docker-builder428014112/test.py:
no such file or directory`
Can anyone help me?
谁能帮我?
回答by Ivan Lee
You should put those files into the same directory with Dockerfile.
您应该将这些文件与 Dockerfile 放在同一目录中。
回答by Brahimi boubakeur
Check if there's a .dockerignore
file, if so, add:
检查是否有.dockerignore
文件,如果有,添加:
!mydir/test.json
!mydir/test.py
回答by Daniel Rogatchevsky
Removing ./
from source path should resolve your issue:
./
从源路径中删除应该可以解决您的问题:
COPY test.json /home/test.json
COPY test.py /home/test.py
回答by lupguo
- Q1: Check your
.dockerignore
file in build path, the files or dir you want to copy may be in the ignore file list! - Q2: The COPY directive is based on the context in which you are building the image, so be aware of any problems with the directory where you are currently building the image! See: https://docs.docker.com/engine/reference/builder/#copy
- Q1:
.dockerignore
在构建路径中检查您的文件,您要复制的文件或目录可能在忽略文件列表中! - Q2:COPY 指令基于您构建映像的上下文,因此请注意当前正在构建映像的目录的任何问题!请参阅:https: //docs.docker.com/engine/reference/builder/#copy
回答by Kumar Abhishek
I was also facing the same, I moved my docker file to root of the project. then it worked
我也面临同样的情况,我将我的 docker 文件移动到项目的根目录。然后它起作用了
回答by Ankit Marothi
In your case removing ./ should solve the issue. I had another case wherein I was using a directory from the parent directory and docker can only access files present below the directory where Dockerfile is presentso if I have a directory structure /root/dir and Dockerfile /root/dir/Dockerfile
在您的情况下,删除 ./ 应该可以解决问题。我有另一种情况,其中我使用父目录中的目录,而 docker 只能访问存在 Dockerfile 的目录下的文件,因此如果我有目录结构 /root/dir 和 Dockerfile /root/dir/Dockerfile
I cannot copy do the following
我无法复制执行以下操作
COPY root/src /opt/src
回答by Mohammed Muneer
In my case, it was the comment line that was messing up the COPY command
就我而言,是注释行弄乱了 COPY 命令
I removed the comment after the COPY command and placed it to a dedicated line above the command. Surprisingly it resolved the issue.
我删除了 COPY 命令之后的注释,并将其放在命令上方的专用行中。令人惊讶的是它解决了这个问题。
Faulty Dockerfile command
错误的 Dockerfile 命令
COPY qt-downloader . # https://github.com/engnr/qt-downloader -> contains the script to auto download qt for different architectures and versions
Working Dockerfile command
工作 Dockerfile 命令
# https://github.com/engnr/qt-downloader -> contains the script to auto download qt for different architectures and versions
COPY qt-downloader .
Hope it helps someone.
希望它可以帮助某人。
回答by Keyur Vyas
This may help someone else facing similar issue.
这可能会帮助面临类似问题的其他人。
Instead of putting the file floating in the same directory as the Dockerfile, create a dir and place the file to copy and then try.
与其将文件浮动在与 Dockerfile 相同的目录中,不如创建一个目录并将文件放置到要复制的位置,然后尝试。
COPY mydir/test.json /home/test.json
COPY mydir/test.json /home/test.json
回答by R?fat Erdem Sahin
When using the Docker compose files, publish, publishes to obj/Docker/Publish. When I copied my files there and pointed my Dockerfile to this directory (as generated), it works…
使用 Docker 撰写文件时,发布,发布到 obj/Docker/Publish。当我在那里复制我的文件并将我的 Dockerfile 指向这个目录(生成的)时,它工作......
回答by Tadej
I had to use the following command to start the build:
我不得不使用以下命令来启动构建:
docker build .
docker build .