How to use environment variables in docker compose

后端 未结 13 769
孤街浪徒
孤街浪徒 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条回答
  •  南笙
    南笙 (楼主)
    2020-11-28 01:12

    I have a simple bash script I created for this it just means running it on your file before use: https://github.com/antonosmond/subber

    Basically just create your compose file using double curly braces to denote environment variables e.g:

    app:
        build: "{{APP_PATH}}"
    ports:
        - "{{APP_PORT_MAP}}"
    

    Anything in double curly braces will be replaced with the environment variable of the same name so if I had the following environment variables set:

    APP_PATH=~/my_app/build
    APP_PORT_MAP=5000:5000
    

    on running subber docker-compose.yml the resulting file would look like:

    app:
        build: "~/my_app/build"
    ports:
        - "5000:5000"
    

提交回复
热议问题