+-
Dockerfile是否总是必须放在构建上下文根目录中?
假设我有一个Django项目,并希望创建几个Dockerfiles,它们将使用不同的设置和系统包(不要与 Python库混淆).
要运行应用程序,我必须将完整的项目代码库复制到映像.

现在我看到了Setting up a docker / fig Mesos environment,它启发我将每个单独的Dockerfile放入项目根目录中的自己的目录中.

docker build env1 / predictably创建一个env1的tarball并使用它来构建图像.

有什么办法可以重新定义Dockerfile名称或构建上下文根目录吗?

最佳答案
Docker 1.5引入了“指定要在构建中使用的Dockerfile”的选项:

Specify the Dockerfile to use in build

Contributed by: Doug Davis – Link to PR

This is possibly one of the most requested feature in the past few
months: the ability to specify the file to use in a docker build
rather than relying on the default Dockerfile. docker build -f allows
you to define multiple Dockerfiles in a single project and specify
which one to use at build time. This can be helpful if you require
separate Dockerfiles for testing and production environments.

使用此功能,您不需要为多个Dockerfiles分隔文件夹,因此不再需要为每个Dockerfile提供不同的文件夹.只需在根文件夹中有多个Dockerfiles,并使用-f选项构建每个Dockerfiles.

点击查看更多相关文章

转载注明原文:Dockerfile是否总是必须放在构建上下文根目录中? - 乐贴网