600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > Docker compose 环境变量env_file相关

Docker compose 环境变量env_file相关

时间:2022-07-01 12:08:56

相关推荐

Docker compose 环境变量env_file相关

1. 两个框中设置配置环境变量文件(.env)的方式都可以。

2. 如果选第一种,DOT_ENV_FILE变量的名字一定要这样,不能改。

3. setting.py中的 environ.Env.read_env('heat_conf/settings/production.env'),只有在上述两种方式都未配置的情况下才会生效(优先级低,生产环境非部署的docker环境,所以未配置前两种方式,因此生效)

贴上environ.Env.read_env的部分代码:

# 将 .env 文件中的配置设置到环境变量中

try:with open(env_file) if isinstance(env_file, basestring) else env_file as f:content = f.read()except IOError:warnings.warn("Error reading %s - if you're not configuring your ""environment separately, check this." % env_file)returnlogger.debug('Read environment variables from: {0}'.format(env_file))for line in content.splitlines():m1 = re.match(r'\A(?:export )?([A-Za-z_0-9]+)=(.*)\Z', line)if m1:key, val = m1.group(1), m1.group(2)m2 = re.match(r"\A'(.*)'\Z", val)if m2:val = m2.group(1)m3 = re.match(r'\A"(.*)"\Z', val)if m3:val = re.sub(r'\\(.)', r'\1', m3.group(1))cls.ENVIRON.setdefault(key, str(val))

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。