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

Viewed 210

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?

2 Answers

You can use WORKDIR which will create a directory if it doesn't exists, then run COPY without specifying * (its not needed), just pass the current directory:

WORKDIR /project
COPY . /project
Related