2

I would like to copy multiple directories (with contents) to a single directory in my container while maintaining the original directory structure of my project. For example, the relevant line in my Dockerfile looks like this:

COPY bin env project ./projects/

The command above only copies files into my projects directory and also removes all of the original directory structure of bin, env, and project.

How can I copy several directories (with contents) such that the original directory structures are preserved? I did find this reference, but as the first commenter points out, directory structure is lost with this method.

turtle
  • 7,533
  • 18
  • 68
  • 97

1 Answers1

1

you need to create the directory structure since COPY will only add files not the directory itself. one approach will be aading them one by one.

RUN mkdir -p projects/{bin,env,project}
COPY bin projects/
COPY env projects/
COPY project projects/

or maybe using ADD will be a better approach since Add will decompress archives download files and more. so you will need to archive directories first, then use add like below

ADD archive.tgz projects/
Arash
  • 320
  • 2
  • 10