Docker主机的弹性Beanstalk环境变量 [英] Elastic Beanstalk environment variables for Docker host
问题描述
如何将EB env变量公开到Docker主机?
这是一个,所以我发布我的解决方案为那些遇到这个。
弹性Beanstalk Docker实例不公开环境变量到docker主机。它只对docker容器执行。
如果要在主机上获取env变量,它们位于 / opt / elasticbeanstalk / deploy / configuration / containerconfiguration
。
这是一个大的JSON文件,方便不遵守env vars的JSON结构。
我写了一个小ruby脚本解析它,并从中提取env vars:
require'json'
pre>
container_config = JSON.parse (File.read('/ opt / elasticbeanstalk / deploy / configuration / containerconfiguration'))
raw_vars = container_config ['optionsettings'] ['aws:elasticbeanstalk:application:environment']
envs =''
raw_vars.each do | raw_var |
pair = raw_var.split('=')
envs<<< export#{pair [0]} =#{pair [1]} \\\
if pair [1]
end
puts envs
此脚本产生一组导出命令到控制台,以设置env vars。我修改了一下,将
ENV
命令写入我的Dockerfile
。I have an EB env with Docker web app (rails) properly deployed. I set several EB env variables and they are properly visible in the container. Now - I'd like these EB env variables to be visible to the EC2 instance host, so that I can use them in the docker build process. However, they are not exposed to the docker host, only to the container.
How do I expose EB env variables to the Docker host?解决方案This was a though one, so I'm posting my solution for those who encounter this.
Elastic Beanstalk Docker instance does not expose the environment variables to the docker host. It does that only to the docker container.
If you'd like to get the env variables on the host, they are located at/opt/elasticbeanstalk/deploy/configuration/containerconfiguration
.
This is one large JSON file, conveniently disobeying the JSON structure for the env vars.
I wrote a small ruby script to parse it and extract the env vars from it:require 'json' container_config = JSON.parse(File.read('/opt/elasticbeanstalk/deploy/configuration/containerconfiguration')) raw_vars = container_config['optionsettings']['aws:elasticbeanstalk:application:environment'] envs = '' raw_vars.each do |raw_var| pair = raw_var.split('=') envs << "export #{pair[0]}=#{pair[1]}\n" if pair[1] end puts envs
this script yields a set of export commands to console that sets the env vars. I adapted it a bit to write
ENV
commands into myDockerfile
.这篇关于Docker主机的弹性Beanstalk环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!