-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include unset variables when parsing env_file #2259
Conversation
Those can be used to override (remove) variable from container just like --env do Signed-off-by: Nicolas De Loof <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Looks like the behavior changed between docker cli v1.4.x and v1.5.x docker build -t foo -<<EOF
FROM busybox
ENV ENV_VAR_IN_IMAGE=image_value
EOF Docker 1.4 sets the variable to docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock --entrypoint=/bin/sh docker:1.4
/ # docker --version
Docker version 1.4.1, build 5bc2ff8
/ # docker run --rm foo sh -c 'env | grep ENV_VAR_IN_IMAGE || echo variable not set'
ENV_VAR_IN_IMAGE=image_value
/ # docker run --rm -e ENV_VAR_IN_IMAGE foo sh -c 'env | grep ENV_VAR_IN_IMAGE || echo variable not set'
ENV_VAR_IN_IMAGE=
/ # docker run --rm -e ENV_VAR_IN_IMAGE= foo sh -c 'env | grep ENV_VAR_IN_IMAGE || echo variable not set'
ENV_VAR_IN_IMAGE=
/ # ENV_VAR_IN_IMAGE=override docker run --rm -e ENV_VAR_IN_IMAGE foo sh -c 'env | grep ENV_VAR_IN_IMAGE || echo variable not set'
ENV_VAR_IN_IMAGE=override
/ # docker run --rm -e NEW_ENV_VAR foo sh -c 'env | grep NEW_ENV_VAR || echo variable not set'
NEW_ENV_VAR=
/ # docker run --rm -e NEW_ENV_VAR= foo sh -c 'env | grep NEW_ENV_VAR || echo variable not set'
NEW_ENV_VAR=
/ # NEW_ENV_VAR=from_environment docker run --rm -e NEW_ENV_VAR foo sh -c 'env | grep NEW_ENV_VAR || echo variable not set'
NEW_ENV_VAR=from_environment Whereas docker 1.5 and up unset the env-var when using docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock docker:1.5 sh
/ # docker --version
Docker version 1.5.0, build a8a31ef
/ # docker run --rm foo sh -c 'env | grep ENV_VAR_IN_IMAGE || echo variable not set'
ENV_VAR_IN_IMAGE=image_value
/ # docker run --rm -e ENV_VAR_IN_IMAGE foo sh -c 'env | grep ENV_VAR_IN_IMAGE || echo variable not set'
variable not set
/ # docker run --rm -e ENV_VAR_IN_IMAGE= foo sh -c 'env | grep ENV_VAR_IN_IMAGE || echo variable not set'
ENV_VAR_IN_IMAGE=
/ # ENV_VAR_IN_IMAGE=override docker run --rm -e ENV_VAR_IN_IMAGE foo sh -c 'env | grep ENV_VAR_IN_IMAGE || echo variable not set'
ENV_VAR_IN_IMAGE=override
/ # docker run --rm -e NEW_ENV_VAR foo sh -c 'env | grep NEW_ENV_VAR || echo variable not set'
variable not set
/ # docker run --rm -e NEW_ENV_VAR= foo sh -c 'env | grep NEW_ENV_VAR || echo variable not set'
NEW_ENV_VAR=
/ # NEW_ENV_VAR=from_environment docker run --rm -e NEW_ENV_VAR foo sh -c 'env | grep NEW_ENV_VAR || echo variable not set'
NEW_ENV_VAR=from_environment |
While the
The behavior above is (I think) consistent with # by default, the image runs with `LOG_LEVEL=error`
docker run -d -e LOG_LEVEL some_image
# but this can be overridden from the current environent
export LOG_LEVEL=debug
docker run -d -e LOG_LEVEL some_image |
- What I did
Made --env_file consistent with --env regarding unset variables
Close #2254
Also see #1019
- How I did it
unset variables (VAR without a
=
) which can't be resolved to a value by emptyFn are not excluded from result, so that they can override container environment the same way --env do.This is consistent with https://docs.docker.com/engine/reference/commandline/run/#set-environment-variables--e---env---env-file
- How to verify it
Dockerfile:
env_file:
docker run
and confirm FOO is set by image in container environmentdocker run --env FOO
and confirm FOO is not set in container environmentdocker run --env_file foo.env
and confirm FOO is not set in container environment- Description for the changelog
Fix environment file parsing for empty variables.
- A picture of a cute animal (not mandatory but encouraged)