[英]lstate error: no such file or directory while building Docker from a custom image with Docker build command
I have create a custom image for lamp stack with following files 我已经为灯堆创建了一个自定义图像,其中包含以下文件
apps.conf
Dockerfile
entrypoint.sh
start.sh
supervisord.conf
Dockerfile
was create with ENV, RUN, ADD and CMD command. Dockerfile
是使用ENV,RUN,ADD和CMD命令创建的。
Each application installed successfully, but stuck it at ADD command and check the given path which is correct. 每个应用程序安装成功,但将其粘贴在ADD命令并检查给定的路径是否正确。
ADD /home/ktpl/nayan/MyLamp/supervisord.conf /etc/supervisor/supervisord.conf
ADD /home/ktpl/nayan/MyLamp/apps.conf /etc/supervisor/conf.d/apps.conf
ADD /home/ktpl/nayan/MyLamp/entrypoint.sh /entrypoint.sh
ADD /home/ktpl/nayan/MyLamp/start.sh /start.sh
Process is stuck at Add command.: 进程停留在添加命令:
lstat home/ktpl/nayan/lamp/supervisord.conf: no such file or directory
Docker builds always work relative to the context - ie the directory you pass in the docker build
command. Docker构建始终相对于上下文工作 - 即您在
docker build
命令中传递的目录。 You cannot use absolute paths in ADD , you should be specifying the source file relative to the build context. 您不能在ADD中使用绝对路径 ,您应该指定相对于构建上下文的源文件。
For local files you should use COPY instead of ADD too, so your Dockerfile becomes: 对于本地文件,您应该使用COPY而不是ADD ,因此您的Dockerfile变为:
COPY ./supervisord.conf /etc/supervisor/supervisord.conf
#etc.
And then you build it from your MyLamp directory with docker build -t my-tag .
然后使用docker
docker build -t my-tag .
从MyLamp目录构建它docker build -t my-tag .
ADD
can be used to copy local files to image while building. ADD
可用于在构建时将本地文件复制到映像。
Couple of things: 几件事:
/home/ktpl/nayan/lamp
is the valid directory /home/ktpl/nayan/lamp
是有效目录 /home/ktpl/nayan/MyLamp
exists and files present in there. /home/ktpl/nayan/MyLamp
存在且文件存在于那里。 As per the documentation of docker 根据docker的文档
The path must be inside the context of the build;
路径必须位于构建的上下文中; you cannot ADD ../something /something, because the first step of a docker build is to send the context directory (and subdirectories) to the docker daemon.
你不能添加../something / something,因为docker构建的第一步是将上下文目录(和子目录)发送到docker守护进程。
If your files are in the same directory as you build image, then you may use below statements in Dockerfile
如果您的文件与构建映像位于同一目录中,则可以在
Dockerfile
使用以下语句
ADD ./supervisord.conf /etc/supervisor/supervisord.conf
ADD ./apps.conf /etc/supervisor/conf.d/apps.conf
ADD ./entrypoint.sh /entrypoint.sh
ADD ./start.sh /start.sh
Of course, like it was mentioned in the other answer, COPY
can also be used. 当然,就像在其他答案中提到的那样,也可以使用
COPY
。
Sample Dockerfile
contents: 示例
Dockerfile
内容:
FROM busybox
ADD ./test.txt /test.txt
CMD ls /
You can building image and running it shows file being added in the below image. 您可以构建图像并运行它显示在下图中添加的文件。
If all the files and directories present and still you see this problem, then check .dockerignore
has entry for the same. 如果存在所有文件和目录但仍然看到此问题,则检查
.dockerignore
是否具有相同的条目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.