Use docker-compose env variable in Dockerbuild file

后端 未结 3 620
粉色の甜心
粉色の甜心 2020-12-24 12:40

Having the following docker-compose file:

db:
    build: .
    environment:
        - MYSQL_ROOT_PASSWORD=password
        - ENV=test
    env_file: .env
         


        
3条回答
  •  爱一瞬间的悲伤
    2020-12-24 13:26

    It works ok this way:

    docker-compose.yml

    version: '3.5'
    
    services:
        container:
            build:
                context: .
                args:
                    ENV: ${ENV} # from .env file
            env_file:
                - .env
    

    Dockerfile

    # from compose args
    ARG ENV 
    ADD ${ENV}/data.xml /data/
    

    .env

    ENV=myenv
    

    Thus all the values are taken from .env file

提交回复
热议问题