带有文件遍历的Docker COPY [英] docker COPY with file globbing
问题描述
在dockerfile内,我想为通过globlob定义的文件指定复制操作,并且我希望它也与路径一起复制.所以,像这样:
Inside the dockerfile, I want to specify a copy operation for files which are defined by globbing and I want it to be copied with the path as well. So, something like this:
COPY ./src/**/project.json /app/**/
考虑到我具有以下结构:
Considering I have the following structure:
./src/bar/project.json
./src/foo/project.json
目的地应如下所示:
/app/bar/project.json
/app/foo/project.json
但是显然,这是行不通的,如果有机会,我真的不想单独指定所有COPY操作.知道怎么做吗?
but apparently, this doesn't work and I really don't want to specify all of the COPY operations separately if I have a chance. Any idea how to do this?
请注意,我基本上无法通过
.dockerignore
按照建议忽略其他文件,因为我要复制其他文件破坏软件包安装操作后,从同一文件夹中下载.因此,dockerfile与此类似:
Note that I cannot basically ignore other files through
.dockerignore
as suggested as I am going to copy the other files from the same folder after ruining a package install operation. So, the dockerfile is similar to this:
FROM microsoft/aspnet:1.0.0-rc1-update1
COPY ./src/**/project.json /app/**/
WORKDIR /app/ModernShopping.Auth
RUN ["dnu", "restore"]
ADD ./src /app
EXPOSE 44300
ENTRYPOINT ["dnx", "web"]
推荐答案
对于任何非标准的构建操作,我更喜欢将docker build
命令包装在脚本中(名为"build
").
我会在这里
For any non-standard build operation, I prefer wrapping the docker build
command in a script (named 'build
').
Here I would
- 创建一个子文件夹
tmp
(正好在Dockerfile
旁边,以便将其保留在docker build
上下文中) - 通过以下方式使外壳
cp
:cp ./src/**/project.json tmp
- 呼叫
docker build
,其中Dockerfile
包括COPY tmp/ /app/
- 删除
tmp
.
- create a subfolder
tmp
(just beside theDockerfile
, in order to keep it in thedocker build
context) - make the shell
cp
with globing:cp ./src/**/project.json tmp
- call
docker build
, with aDockerfile
includingCOPY tmp/ /app/
- deleting
tmp
.
这样,在从主机上下文构建映像之前,我先配置了主机所需的内容.
That way, I pre-configure what I need from host, before building the image from the host context.
这篇关于带有文件遍历的Docker COPY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!