如何在Docker中共享环境variables

我对docker工人很陌生,我有很多麻烦让它开始。 我正在为Visual Studio 2017做一个asp.net核心1.0.1应用程序用户docker容器工具。我有以下env.file在与这个值的撰写文件相同的根:

REDIS_PORT=6379 

和这个docker组成yml:

 version: '2' services: haproxy: image: eeacms/haproxy links: - webapplication3 ports: - "80:80" webapplication3: image: webapplication3 enviroment: - REDIS_PORT=${REDIS_PORT} build: context: . dockerfile: Dockerfile links: - redis ports: - "80" redis: image: redis ports: - ${REDIS_PORT} 

我想知道我必须从我的Asp.net核心应用程序连接到的Redis端口。 据我所知,唯一的方法是使用envvariables,因为我不想复制粘贴到任何地方的端口我想使用.env文件样式。 无论如何,这不是说:

 Unsupported config option for services.webapplication3:'enviroment' 

任何想法可能是什么问题?

你在单词environment错过了一个字母“n”。

您需要传递env_file选项:

 version: '2' services: haproxy: image: eeacms/haproxy links: - webapplication3 ports: - "80:80" webapplication3: image: webapplication3 env_file: - env.file environment: - REDIS_PORT=${REDIS_PORT} build: context: . dockerfile: Dockerfile links: - redis ports: - "80" redis: image: redis env_file: - env.file ports: - ${REDIS_PORT} 

看看https://docs.docker.com/compose/environment-variables/了解更多信息。