-
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
Handle quotes in --env-file values consistently with Linux/WSL2 "source"ing #3630
Comments
What's the status on this issue and the corresponding PR? |
Swarm and Compose see the same value differently 😨
$ docker compose up ... with .env_file
$ docker stack deploy ... with .env_file
|
Hopefully this can get fix soon |
Yes, this stumped me for a while as well. Worked nice locally, but not when dockerized. Even more confusing when compose would've handled the variables differently. |
Just run into the same problem, either the script works locally OR in the container, but never in both. This is really useless and forces keeping the same content twice. Please fix this soon. |
Let me copy my comment over from #4665 (comment)
|
@glours do you know if the change in format for |
I've just spent a good while debugging an issue off the back of this, which is colouring my view, but I think this design choice is really confusing —
At the moment, my natural inclination is to expect it to behave as per any other The docs also make it sound as if Personally, I'd much prefer if |
Any updates on this issue ? |
I just ran into this bug today, and it feels like this command should be removed or corrected. It doesn't make sense as is. Especially not according to the documentation |
Do we have any update on this? |
Issue is currently preventing use of the |
I just found this annoyed with the fact that Please fix this. |
an alternative may be to mount the env file itself, instead of giving it to
of course you need to customize path names to your env inside and outside the container. |
A .env-file in the root of a project can used by several different tools
you can source a .env-file in bash via
Although not officially formalized, it is quite universally understood that a .env-file needs to have a bash-compatible syntax. Fixing the quotes only fixes some symptoms. |
I second the notion that |
This behavior is proving to cause all sorts of issues when moving between environments and interpretations of quotes. |
To address Docker CLI's behavior I tried removing the quotes from my env file, which inevitably made all the other dotenv tools break due to some characters in the values. Not an option. As a hackish workaround, I'm currently relying on the shell to interpret/import the env file as expected and, instead of using the # Docker is capable of passing individual environment variables by name.
# Assumes .env has already been sourced.
env_flags="$(cat .env | grep -v -e '^[[:space:]]*$' -e '^#' | cut -d '=' -f 1 | xargs -I{} printf "--env {} ")"
# env_flags=--env SOME_VAR --env ANOTHER_VAR
# Usage:
docker run --rm -it \
-v "$(pwd):/usr/src/app" \
$env_flags \
"my_image:latest"
# Explanation
# `grep -v -e '^[[:space:]]*$' -e '^#'` # removes empty lines and comments
# `cut -d '=' -f 1` # strips the value, only keeping the variable name
# `xargs -I{} printf "--env {} "` # prefixes each variable name with `--env ` This is a very naïve idea (and the example implementation probably fails in many cases), but might be helpful to someone. |
We cannot pass --env-file (docker/cli#3630) so every variable has to be specified explicitly.
I also ran into this issue when trying to run an |
Just ran into the same problem - Docker's |
+1 |
welp, just fell into this trap out of nowhere |
this approach is not intuitive. spent quite a while trying to debug this issue as the env file with quoted values works in docker compose but not regular docker run... the following example demonstrates how it doesn't follow common sense: .env SECRET="mysecret" works for docker compose using services:
myimage:
env_file:
- .env doesnt work for docker run using docker run --env-file .env myimage |
Just adding to this, I ran into the same exact issue today, while trying to debug a service without running docker-dompose and just doing docker run. If no breaking changes are being made on this, at least having an alternative command that parses "" would help! |
I fought for an hour against this feature. It feels strange that i can not pass files i use for user profiles. |
This behavior is really strange, docker run should be fixed. |
@thaJeztah A couple of years ago, you made a PR that didn't hit the mainline. Could you update this issue on its current status and explain why it is not fixed and looks like it never will be? I expect the Docker team to provide a workaround or reflect this issue in documentation. The perfect solution would be to have a warning emitted by docker CLI when it detects that the env file is in a traditional shell format. |
Thank goodness for this thread, I thought I was crazy. Spent a week trying to figure out why an env file would cause a container crash and this turned out to be the issue. Having such a strong inconstancy between |
Importing an I just use Example Here's my
Let's run nginx and confirm the problem.
Now let's use
Much better! The While having to remember the Note that this is GNU |
Hi there,
I use a
.env
file to supply env vars for my application both when running locally and in a Docker container.When running my application in Linux/WSL2 (Ubuntu), I
source
the.env
file before running.Example:
And when running my application in Docker Desktop on Windows I use the --env-file option to specify the
.env
file:Unfortunately, some of the env var values in the
.env
file need to contain spaces. This means they must be double-quoted to work correctly whensource
ing in Linux. However when quoted, the parsing indocker run
does not remove the quotes making the values invalid as they contain literal quote marks at beginning and end.The consequence of this is I need to maintain a second (mostly duplicate)
.env
file for Docker use.I would much prefer if
docker run
could parse.env
files in the same way as my Linuxsource
ing does and in line with the general shell concept that quotes are a guide to how a string should be interpreted - not part of the string itself.From searching, it seems this has been fixed in
docker compose
(docker/compose#8388). Please can you also fix it indocker run
?The text was updated successfully, but these errors were encountered: