Dockfact的12factor配置方法 [英] 12factor config approach with Docker

查看:232
本文介绍了Dockfact的12factor配置方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有使用环境变量来控制Docker行为的本地或普遍接受的方法,即以12因子的方式?



唯一的语言无关的方法看到的是用-e变量来污染docker运行命令。我看到的最可维护的解决方案是使用cat和sed的组合来使用.env文件生成CLI参数: https://twitter.com/DataKyle/status/422843345120296960



我们目前使用Vagrant for dev,一个CI / CD托管供应商进行测试,部署,加上AWS弹性Beanstalk作为分段和生产PAAS。我们的应用程序拥有超过100个可配置参数,其中大部分设置为默认值,但每个环境仍然需要定制大约10-20个。使用这么大的命令行变量列表来运行docker似乎太麻烦了。



此外,它不允许您从Docker主机(例如CI提供商预装的Redis或Postgres凭据)中获取变量,而无需进一步的黑客攻击。



有没有一个解决方案我还没有找到?
或者这是Docker的一个缺失的部分?
或者这在某种程度上是对Docker哲学的理解?

解决方案

Docker 0.10.0和更新版本(2014年4月8日)接受 docker运行--env-file< filename> ,让您可以使用 .env 此外,您可以让码头工作者进一步互动: - 卷从可以挂载所有引用的容器的卷和 - link 可以让容器知道引用容器的外露端口的详细信息。



虽然 Docker运行参考目前有点软弱,但您可以找到所有详细信息在CLI参考的运行部分以及容器链接参考



从什么从容器开始。通常我建议启动一个shell脚本,它设置默认环境变量(沿:$ {ENV:= default_value} 的行),导出它们,然后 exec sa单个可执行文件。这个可执行文件可以是前台所需的应用程序,或像 runit supervisord 之类的init替换。



如果不是系统的一部分,我不建议在你的码头中运行 sshd (例如,gitlab的容器应该包含sshd,因为它通过ssh提供git repo访问)。为了维护或调试目的,我建议使用 nsenter


Is there yet any native or commonly-accepted approaches to using environment variables to control Docker behaviour, i.e. in a 12factor manner?

The only language-agnostic method I've seen is to pollute the docker run command with -e variables. The most maintainable solution I've seen is using a combination of cat and sed to generate the CLI parameters using a .env file: https://twitter.com/DataKyle/status/422843345120296960

We currently use Vagrant for dev, a CI/CD hosted provider for test and deploy, plus AWS Elastic Beanstalk as the Staging and Production PAAS. Our app has over 100 configurable parameters, most of which are set to defaults, but each environment still needs to customise around 10-20 of those. It just seems too hacky to be running docker with a huge list of command-line variables like that.

Further, it doesn't allow you to take variables from the docker host (such as the CI provider's pre-installed Redis or Postgres credentials), without a further hack.

Is there a solution to this I haven't found? Or is this a missing piece for Docker? Or is this somehow philosophically against the Docker philosophy?

解决方案

Docker 0.10.0 and newer (Apr 8, 2014) accepts docker run --env-file <filename>, which lets you feed docker's running environment with .env-like files.

Moreover, you can let dockers to interact further: --volumes-from can mount all volumes from the referenced container, and --link lets the container know the details of the referenced container's exposed ports.

While the Docker run reference is a bit weak at the moment, you can find all the details in the CLI reference's run section, as well as the container linking reference.

As of what to start from the container. Usually I recommend starting a shell script, which sets default environment variables (along the lines of : ${ENV:=default_value}), exports them, then execs a single executable. This executable can be the desired application in the foreground, or an init replacement like runit or supervisord.

I wouldn't recommend running sshd inside your docker, if it's not part of the system (for example, a container for gitlab should contain sshd, as it provides git repo access through ssh). For maintenance or debugging purposes I recommend using nsenter instead.

这篇关于Dockfact的12factor配置方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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