如何传递变量给 docker-compose 文件

2018-11-15 09:02:05 +08:00
 helloworld12

怎么把 redis_test_host 传进去。。。。 我的 ~/.bash_profile 里面已经有下面这一行了

export redis_test_host=xxxx

docker compose 文件

redis-test:
	image: oliver006/redis_exporter:v0.21.2
    environment:
	  # 内网 IP
      - REDIS_ADDR=${redis_test_host}
	  - REDIS_PASSWORD=${redis_test_pwd}
    ports:
	  - "9122:9121"
    deploy:
	  replicas: 1
#      placement:
#        constraints: [node.role == manager]

docker compose 是用来部署服务器上的服务的

部署的命令是:

eval $(docker-machine env remoteSer)
docker stack deploy -c xxxx.yml serviceName

....

发现上述方式生效了。。。

3016 次点击
所在节点    问与答
4 条回复
cctv1005s927
2018-11-15 09:05:16 +08:00
用一个脚本,动态生成 docker-compose.yml 即可
WilliamYang
2018-11-15 09:50:39 +08:00
看文档啊, 老铁, docker-compose.yml 同一个文件夹内放一个.env 文件, 里面写环境变量就可以了
helloworld12
2018-11-15 13:32:32 +08:00
@WilliamYang #2 不方便,因为要上传到 git 进行管理
helloworld12
2018-11-15 13:33:09 +08:00
已经 ok 了, 用了个土方法

source ~/.bash_profile

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/507986

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX