helloworld12
V2EX  ›  问与答

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

  •  
  •   helloworld12 · Nov 15, 2018 · 3824 views
    This topic created in 2768 days ago, the information mentioned may be changed or developed.

    怎么把 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  
       Nov 15, 2018   ❤️ 1
    用一个脚本,动态生成 docker-compose.yml 即可
    WilliamYang
        2
    WilliamYang  
       Nov 15, 2018
    看文档啊, 老铁, docker-compose.yml 同一个文件夹内放一个.env 文件, 里面写环境变量就可以了
    helloworld12
        3
    helloworld12  
    OP
       Nov 15, 2018
    @WilliamYang #2 不方便,因为要上传到 git 进行管理
    helloworld12
        4
    helloworld12  
    OP
       Nov 15, 2018
    已经 ok 了, 用了个土方法

    source ~/.bash_profile
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2670 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 01:13 · PVG 09:13 · LAX 18:13 · JFK 21:13
    ♥ Do have faith in what you're doing.