docker-compose environment not the same as Docker -e

亡梦爱人 提交于 2019-12-11 06:46:50

问题


I am using docker-compose file and want to add some ENV variables to it, which are not related to redis itself.

redis-master:   
    environment:
      - REDIS_REPLICATION_MODE=master
      - ALLOW_EMPTY_PASSWORD=yes
      # Domains
      - VIRTUAL_HOST=redis-master.xxx.com
      - VIRTUAL_PORT=6379
    ports:
      - '6379:6379'
    expose:
      - '6379'
    image: bitnami/redis:latest

But the problem is that this two ENV were not added to Docker: VIRTUAL_HOST and VIRTUAL_PORT

If I am doing like

docker run -d -p 6379:6379 --name redis-master -e VIRTUAL_PORT=6379 --expose 6379 -e VIRTUAL_HOST=redis-master.xxx.com bitnami/redis:latest

then I can see this two ENV. Why? What is the difference?


回答1:


I used your Compose file and I can see the ENVs:

➜  ~ docker-compose up -d
prometherion_redis-master_1 is up-to-date
➜  ~ docker-compose exec redis-master sh
$ env | grep -i virtual
VIRTUAL_HOST=redis-master.xxx.com
VIRTUAL_PORT=6379

If you want to be sure that ENVs are injected: docker inspect <container_id> | jq '.[0].Config.Env' (you need jq installed)



来源:https://stackoverflow.com/questions/53865748/docker-compose-environment-not-the-same-as-docker-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!