docker dockerfile COPY failed: no source files were specified
- 创建Dockerfile
FROM centos
COPY /projects/archives/* /archives/
CMD cd /archives \
&& ./start
- 构建镜像
$ docker build -t archives:test .
- 出现错误
[root@instance-loafw0eo docker]# docker build -t archives:test .
Sending build context to Docker daemon 2.048kB
Step 1/3 : FROM centos
---> 470671670cac
Step 2/3 : COPY /projects/archives/* /archives/
COPY failed: no source files were specified
原因:docker build命令中有上下文概念,不能copy上下文之外的文件
参考:https://www.cnblogs.com/sparkdev/p/9573248.html
4. 修改Dockerfile
FROM centos
COPY ./* /archives/
CMD cd /archives \
&& ./start
- 重新构建
[root@instance-loafw0eo archives]# docker build -t archives:test .
Sending build context to Docker daemon 45.61MB
Step 1/3 : FROM centos
---> 470671670cac
Step 2/3 : COPY ./* /archives/
---> 5d2a9a18f9f8
Step 3/3 : CMD cd /archives && ./start
---> Running in 5a6181a94029
Removing intermediate container 5a6181a94029
---> 40cda49b4ba1
Successfully built 40cda49b4ba1
Successfully tagged archives:test
- 问题解决
在尝试构建Docker自定义镜像时遇到了`COPY failed: no source files were specified`的错误。该问题源于Docker build命令的上下文限制,不能复制上下文之外的文件。解决方案是确保所有需要复制的文件都在Dockerfile的同一目录下或者通过调整上下文路径。参照相关博客,修改Dockerfile后,成功解决了问题。

2394

被折叠的 条评论
为什么被折叠?



