Copy several directories to another directory

旧巷老猫 提交于 2019-12-23 22:26:30

问题


How would you copy several directories to a destination directory in docker? I do not want to copy the directory contents, but the whole directory structure.

The COPY and ADD commands copy the directory contents, flattening the structure, which I do not want. That is, if these are my sources:

.
├── a
│   ├── aaa.txt
│   └── uuu.txt
├── b
│   ├── ooo.txt
│   └── ppp.txt
└── c
    └── jjj.txt

I want this to be deployed to the docker image:

code/
├── a
│   ├── aaa.txt
│   └── uuu.txt
├── b
│   ├── ooo.txt
│   └── ppp.txt
└── c
    └── jjj.txt

I know I can do this:

ADD a /code/a
ADD b /code/b
ADD c /code/c

But this is, compared to the linux cp command, too verbose. It also creates unnecessary layers.

Is there a better way?


回答1:


You can do:

COPY ./ /code/

It will copy everything from the current folder into the /code folder of your image.

So then you can create .dockerignore file to prevent of adding other files/directories then a, b and c. For example d, e and f are other directories in the current folder which should not be in the result image then content of the .dockerignore file will look like:

Dockerfile*
d
e
f

Disadvantage of this approach is that it will copy also .dockerignore into the /code folder.



来源:https://stackoverflow.com/questions/52605123/copy-several-directories-to-another-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!