添加失败:构建docker映像时无此文件/目录 [英] ADD failed : No such file/Directory while building docker image

查看:238
本文介绍了添加失败:构建docker映像时无此文件/目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Dockerfile以下:

I have below Dockerfile:

FROM python:3

RUN mkdir -p /test/code/
RUN mkdir -p /test/logs/
RUN mkdir -p /test/configs/

ADD test.py /test/code/
ADD test_output.txt /test/code/
ADD test_input.txt /test/configs/
ADD logfile.log /test/logs/


CMD [ "python3", "/test/code/test.py" ]

我的目录结构是:

/home/<username>/test/
                 |-> code/Dockerfile, test_output.txt, test.py
                 |-> logs/logfile.log
                 |-> configs/test_input.txt

当我使用以下命令构建Docker映像时:

when I am building the docker image using below command:

sudo docker build -t myimage .

它显示以下错误:

Step 7/9 : ADD test_input.txt /test/configs/
ADD failed: stat /var/lib/docker/tmp/docker-builder562406652/test_input.txt: no such file or directory

为什么当我拥有目录并且文件也存在时显示此错误。

Why it shows this error when I have the directory and my file is also present.

推荐答案

这不起作用,因为 test_input.txt 不在<一个href = https://docs.docker.com/engine/reference/builder/#usage rel = noreferrer> docker构建上下文。

This doesn't work because test_input.txt is not in the docker build context.

当您执行命令 sudo docker build -t myimage。最后一个。表示构建上下文。泊坞窗的作用是将上下文上载到泊坞窗守护进程以构建映像。在您的情况下,上下文不包含 test_input.txt ,因此不会上载并且docker无法找到文件/

When you execute the command sudo docker build -t myimage . the last '.' indicates the build context. What docker does is that it uploads the context to the docker deamon to build the image. In your case the context does not contain test_input.txt, thus it is not uploaded and docker can't find the file/

有两种方法可以解决此问题:

There are two ways to solve this:


  1. 在内部测试目录中运行命令 sudo docker build- t myimage -f代码/ Dockerfile。。在这种情况下,上下文包括所有测试目录。然后修改Dockerfile以解决此更改:

  1. Inside test directory run the command sudo docker build -t myimage -f code/Dockerfile .. In this case the context includes all the test directory. Then modify the Dockerfile to account for this change:







FROM python:3
...    
ADD code/test.py /test/code/
ADD code/test_output.txt /test/code/
ADD config/test_input.txt /test/configs/
ADD logs/logfile.log /test/logs/




  1. 第二个选项是简单地将Dockerfile移动到测试文件夹并按上述进行修改。在那种情况下,命令 sudo docker build -t myimage。应该可以工作。

  1. The second option is to simply move the Dockerfile to the test folder and modify it as above. In that case the command sudo docker build -t myimage . should work.

这篇关于添加失败:构建docker映像时无此文件/目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆