带有文件遍历的Docker COPY [英] docker COPY with file globbing

查看:258
本文介绍了带有文件遍历的Docker COPY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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 the Dockerfile, in order to keep it in the docker build context)
  • make the shell cp with globing: cp ./src/**/project.json tmp
  • call docker build, with a Dockerfile including COPY 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆