Skip to content
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

env-file has quoting problems #1208

Open
2 of 3 tasks
EvanCarroll opened this issue Feb 21, 2021 · 2 comments
Open
2 of 3 tasks

env-file has quoting problems #1208

EvanCarroll opened this issue Feb 21, 2021 · 2 comments

Comments

@EvanCarroll
Copy link

EvanCarroll commented Feb 21, 2021

  • This is a bug report
  • This is a feature request
  • I searched existing issues before opening this one

Expected behavior

That env-file works the same way as the shell

echo 'FOO="bar"' > .env

set -o allexport
. ./.env
set +o allexport

echo $FOO # returns "bar"

Actual behavior

Quotes are interpreted literally rather as quote characters. If you

$ echo 'FOO="bar"' > .env

Then the $FOO inside the container is set to "bar" (with quotes) rather than bar.

Steps to reproduce the behavior

$ echo 'FOO="bar"' > .env
$ docker run --rm --env-file .env $IMG sh -c 'echo $FOO'
"bar"

See also containers/podman#9446

@thaJeztah
Copy link
Member

First of all, note that the .env file (as used by compose) has different semantics than --env-file. For example (if I'm not mistaken) .env files "ignore" export xx lines, so there might always be some discrepancy.

As to handling of quotes; if I remember correctly, the original implementation (moby/moby#4174) both matched the behavior of ENV (in the Dockerfile syntax), which at that time did not handle quoting (everything after = was taken as literal value, including quotes).

There was some discussion around quoting on the original PR (also related to wether or not newlines should be expanded (similar to echo -e "string\nwith\nnewlines")), but it was decided to limit the format to a line-based format, only using = to separate "name" from "value".

That said, it's a long time since that pull requests, and there have been other requests to allow more flexibility (moby/moby#12997), but there was a fear of introducing feature-creep; what's mostly needed for changes to happen in this area is a proposal / design to see if it's possible to change while remaining backward compatible; moby/moby#12997 (comment)

@EvanCarroll
Copy link
Author

EvanCarroll commented Feb 22, 2021

I would argue that simply not providing quoting will be very confusing as it violates all industry expectations of "env file" (or more specifically a "dot env" file). I don't know if there is a spec ,the idea comes from 12 Factor App, but all of the implementations function differently. If compose has different semantics for it's .env file, I would wonder why they're not implemented in the same fashion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants