-
Notifications
You must be signed in to change notification settings - Fork 86
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
Docker sets environment variable from --env-file to zero-length-string that was meant to be taken if exported only #284
Comments
tere is a flaw w/ docker run - or at least it could be seen as flaw - as while following the docs for --env-file automatic handling on .env.dist and .env files it came to the attention that the .env.dist file not setting any values will not as documented only set the variable if it is exported but also - and that came by surprise - if not exported, the variable is set to an empty string despite of the lack of the quality sign. refs: - docker/for-linux#284
tere is a flaw w/ docker run - or at least it could be seen as flaw - as while following the docs for --env-file automatic handling on .env.dist and .env files it came to the attention that the .env.dist file not setting any values will not as documented only set the variable if it is exported but also - and that came by surprise - not exported variables are set to an empty string despite of the lack of the equality sign. refs: - docker/for-linux#284
there is a flaw w/ docker run - or at least it could be seen as one - as while following the docs for --env-file automatic handling on .env.dist and .env files in the pipelines project it came to the attention that the .env.dist file not setting any values will not as documented only set the variable if it is exported but also - and that came by surprise - not exported variables are set to an empty string despite of the lack of the equality sign. refs: - docker/for-linux#284
I could spot the cause in the code-base. In
(from go docs, highlight and link by me) As Additionally while reviewing the code, it looks like it is prone to not detecting zero-length variable names. It should either bail out in such a case (e.g.
is a follow-up error message I can provoke when tampering with it. I guess this should be addressed on its own, but didn't wanted to get this finding undocumented while stumbling over it. |
previously docker did import environment variables if they were present but created them if they were not when it was asked via a --env-file cli option to import but not create them. fix is to only import the variable into the environment if it is present. additionally do not import variable names of zero-length (which are lines w/ a potential variable definition w/o a variable name). refs: - docker/for-linux#284
previously docker did import environment variables if they were present but created them if they were not when it was asked via a --env-file cli option to import but not create them. fix is to only import the variable into the environment if it is present. additionally do not import variable names of zero-length (which are lines w/ a potential variable definition w/o a variable name). refs: - docker/for-linux#284 Signed-off-by: Tom Klingenberg <[email protected]>
previously docker did import environment variables if they were present but created them if they were not when it was asked via a --env-file cli option to import but not create them. fix is to only import the variable into the environment if it is present. additionally do not import variable names of zero-length (which are lines w/ a potential variable definition w/o a variable name). refs: - docker/for-linux#284 Signed-off-by: Tom Klingenberg <[email protected]>
I could provide a patch which addresses both issues, just tested it. First of all the reason of the original report:
And then for the zero-length variable name:
|
there is a flaw w/ docker run - or at least it could be seen as one - as while following the docs for --env-file automatic handling on .env.dist and .env files in the pipelines project it came to the attention that the .env.dist file not setting any values will not as documented only set the variable if it is exported but also - and that came by surprise - not exported variables are set to an empty string despite of the lack of the equality sign. refs: - docker/for-linux#284 - https://docs.docker.com/engine/reference/commandline/run/#set-environment-variables--e---env---env-file
previously docker did import environment variables if they were present but created them if they were not when it was asked via a --env-file cli option to import but not create them. fix is to only import the variable into the environment if it is present. additionally do not import variable names of zero-length (which are lines w/ a potential variable definition w/o a variable name). refs: - docker/for-linux#284 Signed-off-by: Tom Klingenberg <[email protected]>
previously docker did import environment variables if they were present but created them if they were not when it was asked via a --env-file cli option to import but not create them. fix is to only import the variable into the environment if it is present. additionally do not import variable names of zero-length (which are lines w/ a potential variable definition w/o a variable name). refs: - docker/for-linux#284 Signed-off-by: Tom Klingenberg <[email protected]>
previously docker did import environment variables if they were present but created them if they were not when it was asked via a --env-file cli option to import but not create them. fix is to only import the variable into the environment if it is present. additionally do not import variable names of zero-length (which are lines w/ a potential variable definition w/o a variable name). refs: - docker/for-linux#284 Signed-off-by: Tom Klingenberg <[email protected]>
previously docker did import environment variables if they were present but created them if they were not when it was asked via a --env-file cli option to import but not create them. fix is to only import the variable into the environment if it is present. additionally do not import variable names of zero-length (which are lines w/ a potential variable definition w/o a variable name). refs: - docker/for-linux#284 Signed-off-by: Tom Klingenberg <[email protected]>
previously docker did import environment variables if they were present but created them if they were not when it was asked via a --env-file cli option to import but not create them. fix is to only import the variable into the environment if it is present. additionally do not import variable names of zero-length (which are lines w/ a potential variable definition w/o a variable name). refs: - docker/for-linux#284 Signed-off-by: Tom Klingenberg <[email protected]> Upstream-commit: 96c026eb301f4f9d2cb224d0ee1a2312b7f5b60c Component: cli
This is a bug report I could not find the string " --env-file" with the issue search provided by this project (for opened and closed issues).
Expected behavior
Docker run only takes over exported environment variables values.
Actual behavior
Docker run creates the environment variable when it was not exported.
Steps to reproduce the behavior
Create a environment file that contains a line w/ a variable name but no equality sign , e.g.:
Then execute the run command, print out all variables that start with
VAR
:As the output shows, the variable
VAR3
is set to an empty string even though it was not exported on the host:Output of
docker version
:Output of
docker info
:References:
The text was updated successfully, but these errors were encountered: