2017-01-15 36 views
1

我对码头工人很陌生,我有很多麻烦让它开始。 I'm制造asp.net芯1.0.1应用用户搬运工容器工具,用于视觉工作室2017我在相同的根以下env.file为与此值撰写的文件:如何在Docker中共享环境变量

REDIS_PORT=6379 

和这docker compose 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端口。据我所知,唯一的方法是使用env变量,因为我不想复制粘贴到任何地方我喜欢使用.env文件样式的端口。无论如何这不是说:

Unsupported config option for services.webapplication3:'enviroment' 

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

回答

2

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

+0

谢谢你们,只是拼错了“n”。现在一切正常! – toroveneno

2

您需要通过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/看看更多的信息。