Docker study notes 16: Dockerfile instructions ADD and COPY introduction

1. ADD instruction

The function of the ADD instruction is to copy files and directories in the host build environment (context) directory, and a URL-marked file to the image.

Its format is: ADD source path destination path

Such as:

copy code
#test
FROM ubuntu
MAINTAINER hello
ADD test1.txt test1.txt
ADD test1.txt test1.txt.bak
ADD test1.txt /mydir/
ADD data1  data1
ADD data2  data2
ADD zip.tar /myzip
copy code

There are the following notes:

1. If the source path is a file and the target path ends with /, docker will treat the target path as a directory and copy the source file to this directory.

If the target path does not exist, the target path will be created automatically.

2. If the source path is a file and the target path does not end with /, docker will treat the target path as a file.

If the target path does not exist, a file will be created with the name of the target path and the content is the same as the source file;

If the target file is an existing file, it will be overwritten with the source file, of course, only the content is overwritten, the file name is still the target file name.

If the target file is actually an existing directory, the source file is copied to that directory. Note that in this case, it is best to show a trailing / to avoid confusion.

3. If the source path is a directory and the target path does not exist, docker will automatically create a directory with the target path and copy the files in the source path directory.

If the target path is an existing directory, docker will copy the files in the source path directory to this directory.

4. If the source file is an archive file (compressed file), docker will automatically decompress it.

 

2. COPY instruction

The function and usage of the COPY instruction and the ADD instruction are similar. It's just that the COPY instruction doesn't do automatic decompression work.

 

http://www.cnblogs.com/51kata/p/5264894.html

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326501618&siteId=291194637