如何在Docker的构建环境之外包含文件? [英] How to include files outside of Docker's build context?

查看:296
本文介绍了如何在Docker的构建环境之外包含文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



从Docker文档中可以看到:


路径必须在构建的上下文之内;您不能ADD
../something/something,因为docker构建的第一步是
将上下文目录(和子目录)发送到docker守护程序。


我不想重组我的整个项目,只是为了适应Docker在这件事上。我想保留所有的Docker文件在同一个子目录中。



此外,Docker还没有(可能永远不会)支持符号链接: Dockerfile ADD命令不跟随主机#1676上的符号链接



我可以想到的唯一其他事情是包括将文件复制到Docker构建上下文中的预构建步骤(并配置我的版本控制以忽略这些文件)。



<有没有什么已知的干净的解决方法呢?必须有一个更好的方法。



谢谢

解决方案

解决这个问题的方法是独立于构建上下文来指定Dockerfile,使用-f。



例如,该命令将给ADD命令访问您的当前目录。

  docker build -f docker-files / Dockerfile。 


How can I include files from outside of Docker's build context using the "ADD" command in the Docker file?

From the Docker documentation:

The path must be inside the context of the build; you cannot ADD ../something/something, because the first step of a docker build is to send the context directory (and subdirectories) to the docker daemon.

I do not want to restructure my whole project just to accommodate Docker in this matter. I want to keep all my Docker files in the same sub-directory.

Also, it appears Docker does not yet (and may not ever) support symlinks: Dockerfile ADD command does not follow symlinks on host #1676.

The only other thing I can think of is to include a pre-build step to copy the files into the Docker build context (and configure my version control to ignore those files).

Is there any known clean workaround for this? There must be a better way.

Thanks

解决方案

The best way to work around this is to specify the Dockerfile independently of the build context, using -f.

For instance, this command will give the ADD command access to anything in your current directory.

docker build -f docker-files/Dockerfile .

这篇关于如何在Docker的构建环境之外包含文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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