docker build: COPY/ADD报错:not a directory
注:本文基于CentOS 6.5 3.10内核,docker版本1.7.1
背景
制作docker镜像时,要把一个文件拷贝至镜像中,可以使用ADD或者COPY命令,但是使用的时候一直报错。
[root@localhost test]# docker build .
Sending build context to Docker daemon 3.072 kB
Sending build context to Docker daemon
Step 0 : FROM gpmidi/centos-6.5---> d7943348aefb
Step 1 : ADD a /root
stat /var/lib/docker/devicemapper/mnt/45f35175c0848980b14929ead6ba6bc3b85b4836c5f0861cd25c9fad7c27e4eb/rootfs/root/a: not a directory
最简单的操作,把当前目录的a文件拷贝至镜像环境中的/root目录,然而就是不成功。
换成COPY也一样报错。
[root@localhost test]# docker build .
Sending build context to Docker daemon 3.072 kB
Sending build context to Docker daemon
Step 0 : FROM gpmidi/centos-6.5---> d7943348aefb
Step 1 : COPY a /root
stat /var/lib/docker/devicemapper/mnt/31d0d0527b091d952147cfb63b8700ef6865b88ae768862e4aa16518f5541101/rootfs/root/a: not a directory
解决方案
在网上找了很久,一度还以为是bug,然而并不是,而是没搞清楚ADD/COPY的用法。在拷贝文件的时候docker是用“/”来区分目录和文件的,也就是“/root”是被当做根目录文件root,“/root/”才被识别为目录。知道这个点后,修改就简单了,在目录最后以斜杆“/”结尾即可。
[root@localhost test]# docker build .
Sending build context to Docker daemon 3.072 kB
Sending build context to Docker daemon
Step 0 : FROM gpmidi/centos-6.5---> d7943348aefb
Step 1 : COPY a /root/---> f6477c17485c
Removing intermediate container 0d5ca33a3bda
Successfully built f6477c17485c
注意事项
在查阅资料时还看到一些其他注意事项,一并记录。
1、拷贝或者添加文件时不能超出当前目录范围,即不能使用以下方式:
ADD ../data/file /home/
COPY /home/a.zip /home/
因为在docker build最开始就将当前上下文环境传给 docker deamon,因此如果使用其他目录,docker deamon无法找到这些文件,这也就是我们使用docker build . ,这个“.”的用意。
2、COPY命令拷贝是原样拷贝,而ADD命令会将压缩包解压。
docker build: COPY/ADD报错:not a directory相关推荐
- Docker拉取镜像报错error pulling image configuration
Docker拉取镜像报错error pulling image configuration 在制作docker镜像的时候出现如下报错: xxx@ubuntu:~/Desktop/a$ docker b ...
- clipse中使用maven插件的时候,运行run as maven build的时候报错:
clipse中使用maven插件的时候,运行run as maven build的时候报错: -Dmaven.multiModuleProjectDirectory system propery is ...
- docker中安装nacos报错 com.alibaba.nacos.shaded.io.grpc.StatusRuntimeException: UNAVAILABLE: io exception
docker中安装nacos报错 com.alibaba.nacos.shaded.io.grpc.StatusRuntimeException: UNAVAILABLE: io exception ...
- Docker下删除镜像报错 (cannot be forced) - image has dependent child images
记录一次docker删除镜像报错: docker rmi 镜像Id 报错: Error response from daemon: conflict: unable to delete ae9561a ...
- git add . 报错‘xxx/’does not have a commit checked out,fatal: adding files failed
使用git新建仓库后想要上传多个项目放在一起,结果git init后git add . 报错: 解决: 将子目录下的.git删除 原因:子目录下有.git 与本目录上传的git冲突了
- 执行npm run build的时候报错怎么办?
执行npm run build的时候报错怎么办? [webpack-cli] Invalid configuration object. Webpack has been initialized us ...
- 【docker】top命令报错 “TERM environment variable not set.”
今天用docker运行top命令报错"TERM environment variable not set." 报错的原因是,top命令的运行需要指定终端类型,也就是一个" ...
- 在docker中启动服务报错:New main PID 558 does not belong to service
在docker中启动服务报错: New main PID 558 does not belong to service, and PID file is not owned by root. Refu ...
- docker部署禅道报错 WARNING: IPv4 forwarding is disabled. Networking will not work.
docker部署禅道 报错 WARNING: IPv4 forwarding is disabled. Networking will not work. 通过 #创建网络后启动禅道服务器 docke ...
最新文章
- 卷积神经网络原理图文详解
- 函数 —— strtok() 例如:按照字符拆分字符串,放入新定义的数组中;按照字符拆分字符串,放入原先的数组中
- data类型的Url格式及Base64编码:把小数据直接嵌入到Url中
- 微信小程序服务(功能)直达是什么?有什么作用?
- Navicat(连接) -1之SSL 设置
- RxSwift之订阅UITableViewCell里的按钮点击事件
- 结构体变量和结构体指针变量作为函数参数传递问题
- leetcode —— 909. 蛇梯棋
- 2018计算机专业考研34所,2018考研:计算机专业全球院校排名公布,上海交通大学竟排第一?...
- 2021-09-02语义分割 实例分割 全景分割
- 如何对萤石云视频解码
- Incapsula reese84 分析与破解
- 高性能网络编程(一)----accept建立连接
- 对残差网络resnet shortcut的解释
- Github即将破百万的PDF:编写高质量代码改善JAVA程序的151个建议
- 《自控力》的读后感作文4000字
- 高一被清华姚班录取,高三委拒谷歌 offer,一个重度网瘾少年到理论计算机科学家的蜕变!......
- 数学符号大全 打不出就复制吧
- MYSQL-数据库管理.1
- 吃透考研数学教材,这6点必须注意!