-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
strange interpretation/parsing of .env file #3702
Comments
It's the same behaviour as the Docker CLI, i.e.
You might want to check docker/docker to see if there's already an issue about it. I found moby/moby#12997, which is currently closed, but if there are other env file parsers out there with different behaviour, there's a strong case for us keeping parity with them. |
Alternatively, you can parse these out using a wrapper script to bootstrap your container to get full shell interpolation with your envfile, e.g. |
Just to convert the bash env.sh to env.docker:
It is annoying docker and docker-compose do not follow the same standard as shell. |
Here's an improved sed invocation, which will ignore "=" characters in a variable's value:
...or if you need to add quotes:
This is useful if you want to keep the file in the broken, unquoted docker format, but use it somewhere else in a shell script. E. g., this will export all variables in the file:
|
|
This is quite strange behavior since .env files are regular BASH ("Shell") scripts. However, BASH ("Shell") offers us powerful features, so let's use it to our advantage in a workaround solution. My solution involves a Dockerfile, an env file, a BASH script file and the The strategy consists of injecting your environment variables using another environment variable set in the Workaround SolutionCreate a DockerfileEXAMPLE
Create an env file (BASH script file)EXAMPLE
Create a BASH script for the ENTRYPOINTEXAMPLE
Injecting your environment variables using the run subcommandEXAMPLE
PLUSThe docker-compose does not have this problem as it uses YAML and YAML does not consider surrounding quotes and double quotes as part of the value of environment variables, which is something that is not done with Done! 😎 |
This is awfully inconvenient and leads to many very hard to debug problems. |
In native Max OS / Unix normally you can write:
and both env vars will be equal (double quotes are omitted/ignored). Also libraries I know that use (parse) .env files work in a same way.
Docker compose however treats double quotes differently when parsing .env file passed as
env_file: .env
indocker-compose.yml
. It does not ignore double quotes and treats them as a part of the string.Is it intentional behaviour or it's a bug? Tested on
docker-compose version 1.5.2, build 7240ff3
.The text was updated successfully, but these errors were encountered: