Here is a simple way to override a variable in your docker-compose.yml file.

Using this syntax it will first try to get the environment variable named “MY_PROFILE” from your computer and pass it to the container, if it’s not set, it will use the value “dev”.

docker-compose.yml

 environment:
    - SPRING_PROFILES_ACTIVE=${MY_PROFILE-dev}

Environment variable "MY_PROFILE" not set

> docker-compose config
 environment:
    - SPRING_PROFILES_ACTIVE=dev

Environment variable "MY_PROFILE" set

> set MY_PROFILE=prod
> docker-compose config
 environment:
    - SPRING_PROFILES_ACTIVE=prod

Versions used

  • Docker: 17.06.0-ce
  • Docker Compose: 1.14.0
  • docker-compose.yml file format: 2.1
  • OS: Windows 10