How to use environment variables in docker compose

后端 未结 13 745
孤街浪徒
孤街浪徒 2020-11-28 01:02

I would like to be able to use env variables inside docker-compose.yml, with values passed in at the time of docker-compose up. This is the example.

I am

13条回答
  •  Happy的楠姐
    2020-11-28 01:11

    Use .env file to define dynamic values in docker-compse.yml. Be it port or any other value.

    Sample docker-compose:

    testcore.web:
           image: xxxxxxxxxxxxxxx.dkr.ecr.ap-northeast-2.amazonaws.com/testcore:latest
           volumes: 
                - c:/logs:c:/logs
           ports:
                - ${TEST_CORE_PORT}:80
           environment:
                - CONSUL_URL=http://${CONSUL_IP}:8500 
                - HOST=${HOST_ADDRESS}:${TEST_CORE_PORT}
    

    Inside .env file you can define the value of these variables:

    CONSUL_IP=172.31.28.151
    HOST_ADDRESS=172.31.16.221
    TEST_CORE_PORT=10002
    

提交回复
热议问题