问题
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