The COPY instruction

The COPY instruction enables you to copy the files from the Docker host to the filesystem of the new image. The following is the syntax of the COPY instruction:

COPY <src> ... <dst> 

The preceding code terms are explained here:

  • <src>: This is the source directory, the file in the build context, or the directory from where the docker build subcommand was invoked.
  • ...: This indicates that multiple source files can either be specified directly or be specified by wildcards.
  • <dst>: This is the destination path for the new image into which the source file or directory will get copied. If multiple files have been specified, then the destination path must be a directory and it must end with a slash (/).

Using an absolute path for the destination directory or a file is recommended. In the absence of an absolute path, the COPY instruction will assume that the destination path will start from the root (/). The COPY instruction is powerful enough for creating a new directory and for overwriting the filesystem in the newly created image.

In the following example, we will copy the html directory from the source build context to /var/www/html, which is in the image filesystem, using the COPY instruction, as shown here:

COPY html /var/www/html 

Here is another example of the multiple files (httpd.conf and magic) that will be copied from the source build context to /etc/httpd/conf/, which is in the image filesystem:

COPY httpd.conf magic /etc/httpd/conf/ 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset