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
The best way is to specify environment variables outside the docker-compose.yml file. You can use env_file setting, and define your environment file within the same line. Then doing a docker-compose up again should recreate the containers with the new environment variables.
Here is how my docker-compose.yml looks like:
services:
web:
env_file: variables.env
Note: docker-compose expects each line in an env file to be in
VAR=VALformat. Avoid usingexportinside the.envfile. Also, the.envfile should be placed in the folder where the docker-compose command is executed.