How to copy the same local folder structure to docker containers?

I’ve been trying to copy a python project to the docker container but when I go inside the container and see, the same folder structure does not exist.

Case in point,

I have a folder structure which looks something like this:

project
    file_1.txt
    file_2.ext
    Dockerfile
    sub_dir_1
        file_1_1.py
        file_1_2.py
    sub_dir_2
        file_2_1.py
        file_2_2.py

But all these files when copied into the docker looks like this

project  
file_1.txt  
file_2.ext  
Dockerfile   
file_1_1.py  
file_1_2.py
file_2_1.py
file_2_2.py  
...  
many_other_files

For copying the files to the container, I’ve added this line in the Dockerfile

COPY ./* /project/

What do I do in order to maintain the folder structure in the docker container? Or is it normal for docker to do such a thing, in which case, what about the code of mine which uses relative path?

Thanks in advance!

Hm … I did a little (successful :wink: ) test:

cat Dockerfile

FROM ubuntu:20.04
RUN mkdir /var/testdir
COPY testdir/ /var/testdir
CMD tail -f /dev/null

What I did was to create a similar file structure with subdirs + files. Then simply add the top-level dir “testdir”
Now, when you run the container and loginto it, you’ll see that all files + structure are present.

Back in my mind I may remember that you need the tailing “/” when adding a top-level dir (and without asterisk) … but I might be wrong on that … :grin:

1 Like

Thanks for the response, this was indeed correct!