docker COPY 与文件通配符 [英] docker COPY with file globbing

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

问题描述

在 dockerfile 中,我想为通过 globbing 定义的文件指定一个复制操作,并且我希望它也与路径一起复制.所以,是这样的:

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/**/

考虑到我有以下结构:

./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 上下文中)
  • 使用 globing 制作 shell 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天全站免登陆