Tuesday, March 12, 2019

Docker Copy Files

When building a Docker image using the Dockerfile, if you need to copy some files from the Docker Engine machine to the Docker Image, you need to use the "correct" source path where the files are located.

Let's say you have the following files:

/mydocker/Dockerfile
/mydocker/file1.sh
/mydocker/file2.sh

you can't specify the following command within your Dockerfile

COPY /mydocker/file1.sh /etc/
COPY /mydocker/file2.sh /etc/

instead, you need to do the following

mkdir /mydocker/resources
mv /mydocker/file1.sh /mydocker/resources
mv /mydocker/file2.sh /mydocker/resources

then, in your Dockerfile, specify the following COPY command

COPY resources /etc/