Given a very simple docker-compose file:
version: '3'
services:
test:
image: busybox
env_file:
- my.env
command: env
And the my.env
file referenced in there:
FOO=BAR
Running docker-compose up
prints as expected (container name prefix defaults to the name of the parent directory):
test_1 | PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
test_1 | HOSTNAME=00dc4fa7f38a
test_1 | FOO=BAR
test_1 | HOME=/root
tmp_test_1 exited with code 0
Overriding the variable from the env_file
from the outside, as in FOO=SOMETHING_ELSE docker-compose up
, will not be reflected in the container though. The output will still contain FOO=BAR
as defined in the my.env
.
Is it possible somehow to override variables defined in the env_file
from the outside, without changing them inside the file? I know that it will work if I extend my docker-compose.yml
file with the line
environment:
- FOO
However, this does not really scale to a larger amount of variables - one always has to make sure that the env_file
and docker-compose.yml
are in sync to prevent nasty bugs.