docker-compose环境与Docker -e不同 [英] docker-compose environment not the same as Docker -e
本文介绍了docker-compose环境与Docker -e不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用docker-compose文件,并想向其中添加一些与Redis本身无关的ENV变量。
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
但是问题是这两个ENV没有添加到Docker中:
VIRTUAL_HOST和VIRTUAL_PORT
But the problem is that this two ENV were not added to Docker: VIRTUAL_HOST and VIRTUAL_PORT
如果我这样做
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
然后我可以看到这两个ENV。为什么?有什么区别?
then I can see this two ENV. Why? What is the difference?
推荐答案
我使用了您的Compose文件,可以看到ENV:
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
如果要确保已注入ENV: docker inspect< container_id> | jq’。[0] .Config.Env
(您需要安装 jq
)
If you want to be sure that ENVs are injected: docker inspect <container_id> | jq '.[0].Config.Env'
(you need jq
installed)
这篇关于docker-compose环境与Docker -e不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文