You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am getting errors below when trying to run docker-compose up. The errors are related to the docker-compose.yml file not the Dockerfile though. How can I make docker-compose.yml access env variables as well?
Thanks
Versions
docker-compose version 1.17.0, build ac53b73
Docker version 17.09.0-ce, build afdb6d4
Errors
WARNING: The MY_IP variable is not set. Defaulting to a blank string.
ERROR: The Compose file 'docker-compose.yml' is invalid because:
services.php.ports is invalid: Port ranges don't match in length
The env_file option only sets environment-variables for the docker container that is started, but environment variable interpolation in the docker-compose file itself is done from actual environment variables set in your shell session.
For example;
export MY_IP=192.168.0.11
export MY_PORT=9000
Then running docker-compose up should work
I notice you're "baking" those values into the container's image; given that these values may change, it's probably better to set them at runtime (unless you really need them during build)
Assuming your php image does not need other build-steps than the ones you showed, you can use the upstream php:7.1-fpm image directly, and set the environment variables for the container at runtime;
Notice that you don't add an = or =some value to the environment variables; omitting the = tells docker-compose to set those environment variables from actual environment variables on the host (if set).
If you don't want to export those environment variables before running, you can also create a .env file in the same directory as the compose-file, and docker compose will read that file when running commands (but be aware that this feature is not supported when deploying your compose file using docker stack deploy)
Hi,
I am getting errors below when trying to run
docker-compose up
. The errors are related to thedocker-compose.yml
file not theDockerfile
though. How can I makedocker-compose.yml
access env variables as well?Thanks
Versions
Errors
variables.env
Dockerfile (vars work here)
docker-compose.yml
The text was updated successfully, but these errors were encountered: