Open ndeloof opened 4 years ago
cc @thaJeztah
Tested with various CLI versions
behaviour changed between 18.09.0 (dump FOO=BAR
, env from image not overridden)
and 18.06.3 (dump FOO=
, env overridden but not removed :-\ )
Change was introduced by https://github.com/docker/cli/commit/96c026eb301f4f9d2cb224d0ee1a2312b7f5b60c cf https://github.com/docker/for-linux/issues/284
Before this, VAR without a value which didn't map to an existing env variable resulted in VAR=
added to parsed lines and override in container environment with empty string.
After change, such a VAR is just ignored, still being inconsistent with -e
At the time of change I was looking into parsing dot env files (--env-files
), not specifically env names (-e
, --env
). From what I remember by the code changes, it was not my understanding that it should have any side-effects on -e, --env
as the changes were in the part of parsing env-files.
However there might have been a similar error in -e, --env
parsing which got unnoticed that time as I didn't focus on that part and/or I was not aware it would have been useful to keep the import line. I'm pretty sure I didn't think about that.
For your change request: It's perhaps better then to first format the line as string and then append it (so the append operation is not two times within the the two if / else branches) so that it becomes more clear that a line has to be added always - present/set or not (unset).
I was not aware at the time of change that imports should be kept. That I remember for sure.
Description
docker run -e FOO
will remove var FOO set by Docker image if no such var exists in user environment. ButFOO
(without=
) in an env_file passed by--env-file
doesn't. Seems this is expected behaviour reading env_file according to https://github.com/docker/cli/blob/master/opts/envfile_test.go#L161-L163Steps to reproduce the issue:
docker build -t bug .
docker run -e FOO bug env
: FOO is removed from container environmentFOO
docker run --env_file foo.env bug env
Describe the results you received:
Describe the results you expected:
FOO removed from container environment
Output of
docker version
:Output of
docker info
:Additional environment details (AWS, VirtualBox, physical, etc.):