V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
helloworld12
V2EX  ›  问与答

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

  •  
  •   helloworld12 · 2018-11-15 09:02:05 +08:00 · 2978 次点击
    这是一个创建于 1960 天前的主题,其中的信息可能已经有所发展或是发生改变。

    怎么把 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
    

    ....

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

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

    source ~/.bash_profile
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3381 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 13:16 · PVG 21:16 · LAX 06:16 · JFK 09:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.