当从Dockerfile 中 build Docker 镜像时候,你可以选择两种指令来添加本地的目录或者文件到你的镜像中:ADD和COPY。这两种指令格式基本相同并且基本是同样的东西.
ADD <src>... <dest>
COPY <src>... <dest>
在这两种情况中,目录或者文件(<src>)被复制并添加到容器的文件系统中的指定路径(<dest>)
ADD指令可以让你使用URL作为<src>参数。当遇到URL时候,可以通过URL下载文件并且复制到<dest>。
ADD的另外一个特性是有能力自动解压文件。如果<src>参数是一个可识别的压缩格式(tar, gzip, bzip2, etc)的本地文件(所以实现不了同时下载并解压),就会被解压到指定容器文件系统的路径<dest>。
有趣的是,URL下载和解压特性不能一起使用。任何压缩文件通过URL拷贝,都不会自动解压。
Currently the ADD command is IMO far too magical. It can add local and remote files. It will sometimes untar a file and it will sometimes not untar a file. If a file is a tarball that you want to copy, you accidentally untar it. If the file is a tarball in some unrecognized compressed format that you want to untar, you accidentally copy it.
COPY不支持URL,也不会特别对待压缩文件。如果build 上下文件中没有指定解压的话,那么就不会自动解压,只会复制压缩文件到容器中。
ADD <src>... <dest>
COPY <src>... <dest>
在这两种情况中,目录或者文件(<src>)被复制并添加到容器的文件系统中的指定路径(<dest>)
ADD指令可以让你使用URL作为<src>参数。当遇到URL时候,可以通过URL下载文件并且复制到<dest>。
ADD的另外一个特性是有能力自动解压文件。如果<src>参数是一个可识别的压缩格式(tar, gzip, bzip2, etc)的本地文件(所以实现不了同时下载并解压),就会被解压到指定容器文件系统的路径<dest>。
有趣的是,URL下载和解压特性不能一起使用。任何压缩文件通过URL拷贝,都不会自动解压。
Currently the ADD command is IMO far too magical. It can add local and remote files. It will sometimes untar a file and it will sometimes not untar a file. If a file is a tarball that you want to copy, you accidentally untar it. If the file is a tarball in some unrecognized compressed format that you want to untar, you accidentally copy it.
COPY不支持URL,也不会特别对待压缩文件。如果build 上下文件中没有指定解压的话,那么就不会自动解压,只会复制压缩文件到容器中。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28624388/viewspace-2138821/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/28624388/viewspace-2138821/