Can .env file make environment variables?
I tried to use a .env file to make environment variable, but it doesn't work. These are my steps: version "3" services: web: image: php-fpm:5.6.30 env_file: - .env This is .env file TEST_ENV="HELLO WORLD" It doesn't work when I start the container: var_dump(getenv("TEST_ENV")); // output NULL
For me it seems to work. Maybe this can help you: ├── docker-compose.yaml ├── .env └── myphp ├── Dockerfile └── script.php My .env file TEST_ENV="HELLO WORLD" My docker-compose.yaml: version: "3" services: web: build: ./myphp env_file: .env So my docker-compose.yaml will build the image myphp. The dockerfile looks like this: FROM php:5.6.30-fpm COPY script.php /var/script.php My script.php <?php var_dump(getenv('TEST_ENV')); exit; Than I perform docker-compose up -d --build. This will build my image and add the php script in it and it will run a container instance of that image. $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 15f0289bfbe8 test_web "docker-php-entryp..." 3 seconds ago Up 1 second 9000/tcp test_web_1 I'm accessing my container $ docker exec -it 15f0289bfbe8 bash And I'm going the the /var folder where I've put my script (check dockerfile) and I'm exexcuting it + also just printing env var: root#15f0289bfbe8:/var/www/html# cd /var/ root#15f0289bfbe8:/var# ls backups cache lib local lock log mail opt run script.php spool tmp www root#15f0289bfbe8:/var# php -f script.php string(13) ""HELLO WORLD"" root#15f0289bfbe8:/var# echo $TEST_ENV "HELLO WORLD" root#15f0289bfbe8:/var#
Why doesn't docker-compose 'down' take an optional [SERVICE…] argument?
why does docker-compose build trigger a rebuild when nothing changed
Disable autostart of docker-compose project
Docker-compose Error-Mean Stack Application won't get loaded with the data from mongodb container
docker-compose Windows volume
Trying to figure out why eslint-watch doesn't work with docker-compose correctly
docker-compose the latest stable version on ubuntu
docker compose environment variable for command
java.net.UnknownHostException: failed to resolve 'inventory-microservice'. Exceeded max queries per resolve 3
What does working_dir tag mean in a docker-compose yml file
If I upgrade an image in docker-compose, will its volumes be lost?
How to solve this docker-compose upgrading error?
Fabric Network - what happens when a downed peer connects back to the network?
Docker-compose and load balancing
Run arguments in Docker Compose
Docker compose file config