Copy a copy of Dockerfile to a subdirectory

I am trying to copy several files and folders into a docker image assembly from my local host.

Files are as follows:

folder1 file1 file2 folder2 file1 file2 

I am trying to make a copy as follows:

 COPY files/* /files/ 

However, all files are placed in / files / is there any way in Docker to save the subdirectory structure and also copy files to their directories?

+182
docker copy dockerfile
May 13 '15 at 13:09
source share
3 answers

Delete the star with COPY, with this Docker file:

 FROM ubuntu COPY files/ /files/ RUN ls -la /files/* 

The structure is:

 $ docker build . Sending build context to Docker daemon 5.632 kB Sending build context to Docker daemon Step 0 : FROM ubuntu ---> d0955f21bf24 Step 1 : COPY files/ /files/ ---> 5cc4ae8708a6 Removing intermediate container c6f7f7ec8ccf Step 2 : RUN ls -la /files/* ---> Running in 08ab9a1e042f /files/folder1: total 8 drwxr-xr-x 2 root root 4096 May 13 16:04 . drwxr-xr-x 4 root root 4096 May 13 16:05 .. -rw-r--r-- 1 root root 0 May 13 16:04 file1 -rw-r--r-- 1 root root 0 May 13 16:04 file2 /files/folder2: total 8 drwxr-xr-x 2 root root 4096 May 13 16:04 . drwxr-xr-x 4 root root 4096 May 13 16:05 .. -rw-r--r-- 1 root root 0 May 13 16:04 file1 -rw-r--r-- 1 root root 0 May 13 16:04 file2 ---> 03ff0a5d0e4b Removing intermediate container 08ab9a1e042f Successfully built 03ff0a5d0e4b 
+308
May 13 '15 at 16:08
source share

Alternatively, you can use "." instead of *, since this will take all the files in the working directory, include folders and subfolders:

 FROM ubuntu COPY . / RUN ls -la / 
+16
Nov 29 '18 at 12:25
source share

To combine the local directory with the directory in the image, do this. This will not delete files already present in the image. It will only add files that are present locally, overwriting files in the image if a file with the same name already exists.

 COPY ./files/. /files/ 
+5
Jul 08 '19 at 19:23
source share



All Articles