helloworld12
V2EX  ›  问与答

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

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

    source ~/.bash_profile
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2177 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 00:11 · PVG 08:11 · LAX 16:11 · JFK 19:11
    ♥ Do have faith in what you're doing.