Dockerfile和dev / test / prod环境 [英] Dockerfile and dev/test/prod environment

查看:521
本文介绍了Dockerfile和dev / test / prod环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要创建可以构建三个不同图像(一时一个)的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构建命令的方法 - 没有找到

  • 使用ONBUILD命令 - 我创建了一个主要文件和三个特定的文件,将特定的conf文件复制到图像中的同一目录(由于与第一点相同的原因,它不起作用) li>
  • 从stdin传递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.

推荐答案

为什么不在你的Docker文件中复制所有3个配置文件,然后 docker run -e config = file1 (或file2或fil e3)并使用config环境变量的值来获取所需的配置文件。检查文档
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运行命令的环境变量的行分隔文件。

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

You can check that environment variable is available with docker run -it -e mytag=abc123 ubuntu:latest env | grep mytag shows mytag=abc123

这篇关于Dockerfile和dev / test / prod环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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