I am trying to use an environment variable in the docker-compose.yml
file. I have a file my-great-env.env
.
Here is how they look:
docker-compose.yml
version: '3.4'
services:
blahblah:
images: greatimage
volumes:
- "${MY_PATH}:c:\\FinalFolder"
my-great-env.env
MY_PATH=C:\the\path\to\folder
When I try to docker run this, I get
The MY_PATH variable is not set. Defaulting to a blank string.
How do I use the environment variables defined in the .env
file in docker-compose.yml
?
There are two aspects of your problem:
docker-compose.yml
file, you have to put them in file named .env
as stated here: https://docs.docker.com/compose/environment-variables/#the-env-file env_file
configuration option to use any file with variables definitions as described here: https://docs.docker.com/compose/environment-variables/#the-env_file-configuration-option BUT! they will be visible only in containers, not in the docker-compose.yml
file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.