lstate error: no such file or directory while building Docker from a custom image with Docker build command
lstate error: no such file or directory while building Docker from a custom image with Docker build command
我已经为 lamp 堆栈创建了一个自定义图像,其中包含以下文件
apps.conf
Dockerfile
entrypoint.sh
start.sh
supervisord.conf
Dockerfile
是使用 ENV、运行、ADD 和 CMD 命令创建的。
每个应用程序都安装成功,但卡在 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
进程卡在添加命令处。:
lstat home/ktpl/nayan/lamp/supervisord.conf: no such file or directory
Docker 构建始终相对于上下文工作 - 即您在 docker build
命令中传递的目录。 You cannot use absolute paths in ADD,您应该指定与构建上下文相关的源文件。
对于本地文件,您也应该使用 COPY instead of ADD,因此您的 Docker 文件变为:
COPY ./supervisord.conf /etc/supervisor/supervisord.conf
#etc.
然后使用 docker build -t my-tag .
从 MyLamp 目录构建它
ADD
可用于在构建时将本地文件复制到镜像中。
两件事:
- 您正在使用当前目录构建图像
- 在您的例子中,
/home/ktpl/nayan/lamp
是有效目录
- 不确定您是否有目录
/home/ktpl/nayan/MyLamp
存在并且文件存在于其中。
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.
如果您的文件与您构建镜像在同一个目录中,那么您可以在 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
当然,就像另一个答案中提到的,COPY
也可以。
样本Dockerfile
内容:
FROM busybox
ADD ./test.txt /test.txt
CMD ls /
您可以构建图像,运行 它在下图中显示正在添加的文件。
如果所有文件和目录都存在,但您仍然看到此问题,请检查 .dockerignore
是否有相同的条目。
我已经为 lamp 堆栈创建了一个自定义图像,其中包含以下文件
apps.conf
Dockerfile
entrypoint.sh
start.sh
supervisord.conf
Dockerfile
是使用 ENV、运行、ADD 和 CMD 命令创建的。
每个应用程序都安装成功,但卡在 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
进程卡在添加命令处。:
lstat home/ktpl/nayan/lamp/supervisord.conf: no such file or directory
Docker 构建始终相对于上下文工作 - 即您在 docker build
命令中传递的目录。 You cannot use absolute paths in ADD,您应该指定与构建上下文相关的源文件。
对于本地文件,您也应该使用 COPY instead of ADD,因此您的 Docker 文件变为:
COPY ./supervisord.conf /etc/supervisor/supervisord.conf
#etc.
然后使用 docker build -t my-tag .
ADD
可用于在构建时将本地文件复制到镜像中。
两件事:
- 您正在使用当前目录构建图像
- 在您的例子中,
/home/ktpl/nayan/lamp
是有效目录 - 不确定您是否有目录
/home/ktpl/nayan/MyLamp
存在并且文件存在于其中。
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.
如果您的文件与您构建镜像在同一个目录中,那么您可以在 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
当然,就像另一个答案中提到的,COPY
也可以。
样本Dockerfile
内容:
FROM busybox
ADD ./test.txt /test.txt
CMD ls /
您可以构建图像,运行 它在下图中显示正在添加的文件。
如果所有文件和目录都存在,但您仍然看到此问题,请检查 .dockerignore
是否有相同的条目。