Dockerfile copy keep subdirectory structure Dockerfile copy keep subdirectory structure docker docker

Dockerfile copy keep subdirectory structure


Remove star from COPY, with this Dockerfile:

FROM ubuntuCOPY files/ /files/RUN ls -la /files/*

Structure is there:

$ docker build .Sending build context to Docker daemon 5.632 kBSending build context to Docker daemon Step 0 : FROM ubuntu ---> d0955f21bf24Step 1 : COPY files/ /files/ ---> 5cc4ae8708a6Removing intermediate container c6f7f7ec8ccfStep 2 : RUN ls -la /files/* ---> Running in 08ab9a1e042f/files/folder1:total 8drwxr-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 8drwxr-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 ---> 03ff0a5d0e4bRemoving intermediate container 08ab9a1e042fSuccessfully built 03ff0a5d0e4b


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

FROM ubuntuCOPY . /RUN ls -la /


To merge a local directory into a directory within an image, do this.It will not delete files already present within the image. It will only add files that are present locally, overwriting the files in the image if a file of the same name already exists.

COPY ./files/. /files/