Dockerfile 和 dev/test/prod 环境 [英] Dockerfile and dev/test/prod environment
问题描述
我想创建 Dockerfile,它能够构建三个不同的映像(目前一个).这些图像仅在配置文件中有所不同.
I want to create Dockerfile that will be able to build three different images (one at the moment). Those images differs only in configuration files.
我在尝试:
- 创建三个不同的 docker 文件(不起作用,因为 dockerfile 需要命名为 Dockerfile 并且位于上下文根目录中
- 找到一种将参数传递给 docker build 命令的方法 - 没有找到
- 使用 ONBUILD 命令 - 我创建了一个主文件和三个特定的文件,它们将特定的 conf 文件复制到图像中的同一目录中(由于与第一点相同的原因,它不起作用)
- 从标准输入传递 docker 文件——它不起作用,因为没有上下文(所以我不能使用 ADD/COPY 命令)
我必须说我的想法已经用完了:/你是如何处理这种情况的.在我看来,这应该是一个普遍的问题.
I must say I run out of ideas:/ How do you handle that situation. In my opinion it should be a common issue.
推荐答案
为什么不在你的 Dockerfile 中复制所有 3 个配置文件,然后 docker run -e config=file1
(或 file2 或 file3)并使用配置环境变量的值来获取所需的配置文件.检查文档http://docs.docker.com/reference/commandline/cli/#run
Why not copy in your Dockerfile all 3 config files, and then docker run -e config=file1
(or file2 or file3) and use the value of config environment variable to get the required config file .Check the doc
http://docs.docker.com/reference/commandline/cli/#run
您也可以使用 --env-file=[] 读取环境变量的行分隔文件
docker run
命令.
You can also use the --env-file=[] Read in a line delimited file of environment variables
of the docker run
command.
您可以使用 docker run -it -e mytag=abc123 ubuntu:latest env | 检查环境变量是否可用grep mytag
显示 mytag=abc123
这篇关于Dockerfile 和 dev/test/prod 环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!