Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set an environment variable for docker-compose in Intellij?

I cannot seem to find a way to set an environment variable that can be used in docker-compose in Intellij (Ultimate 2017.3 macos). If I add a .env file to the folder in which docker-compose.yml resides, then it is not picked up by Intellij. Also if I do 'export MYVARIABLE=foo' in a terminal it is not picked up by the Intellij docker plugin. Docker and docker-compose work fine both within or outside Intellij, the only thing is this environment variable substitution does not work in Intellij.

It keeps on saying: The MYVARIABLE variable is not set. Defaulting to a blank string.

In my docker-compose.yml I have a reference to ${MYVARIABLE} and outside Intellij it works fine.

like image 349
user1120821 Avatar asked Dec 11 '25 15:12

user1120821


1 Answers

The Docker-compose run configuration will identify environment files with the .env suffix if they are located in the same directory as the Docker Compose file.

https://www.jetbrains.com/help/idea/docker.html#using-docker-compose

Put MYVARIABLE=test to .env file.

In your .env file :

MYVARIABLE=test

NGINX_PORT=80
MYSQL_PORT=3306
ADMINER_PORT=8080
...

See https://github.com/codeliner/php-ddd-cargo-sample/ 's docker-composer.yml and .env.dist

In my case copy .env.dist to .env

like image 66
Kiwha Um Avatar answered Dec 14 '25 03:12

Kiwha Um



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!