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:


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


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!