-
Notifications
You must be signed in to change notification settings - Fork 18.7k
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 cannot pass newlines from variables in --env-file
files
#12997
Comments
--env-file
files--env-file
files
investigating.... |
Cool, thanks duglin. I moved to its own issue as it seemed more specific to |
yup plus now we won't forget about it ;-) |
In looking at this I think converting \n into a LF for the env-file might be an issue. In all of the examples we're playing with I believe its bash that's actually converting the \n into a LF and not Docker or even normal string analysis. For example, $'hello\nworld' doesn't work in sh. And it only works in the '-e' case because we're letting bash do it for us before Docker sees it. I don't think its possible to get a LF in an env var from within a Dockerfile either. I wouldn't mind making the change if we could justify it as a normal sh thing to do, and if it doesn't break people, but I'm not sure we can. ping @erikh @tiborvass what do you guys think? |
With Compose, for example, you get this behavior:
and this is because in YAML, if you have a quoted string with
My ugly hack at the moment to workaround this is to use |
that's really interesting and consistent with the pattern of "something else before Docker converting it to a LF". I'm really torn. I do want to help and see if we can find a solution for you but at the same time I don't want to muck things up either by adding complexity or break existing users. Just brainstorming.... one option I thought of would be to add some kind of comment/directive to the env-file to indicate that you want escaped sequences converted. This shouldn't break backwards compatibility. One concern I have with this though, is that we now have this ability via env-file but not via -e or even within Dockerfiles. Granted we could claim that if you want support for it via -e then use bash and Would like to hear from @tiborvass, @tianon and @erikh on this entire thread though. |
I think you've summarized my concerns well, @duglin. There's not really a
common syntax for this that I'm aware of besides the $'...' you mentioned
already, and supporting that all over the place definitely feels like even
further feature creep IMO (especially since it's not a generic "/bin/sh"
feature except where "/bin/bash" is "/bin/sh").
|
Another alternative is the ability to declare a variable on multiple lines, which'd allow you to put an actual newline in there. If
|
tricky. That certainly would make it align more with normal sh parsing. Of course, it would mean another parser since I don't think any of our existing ones support crossing lines w/o a \ at the end. But hey, what's one more parser! :-) @tianon @tiborvass @erikh any comments? |
Sorry for the inconvenience but I would rather go the conservative route on this one :( The problem can be solved with I'm going to close this issue, but feel free to continue the discussion and speak up if you disagree. |
I think
|
w/o stating whether I think we should be smarter or not while processing these files :-) since we just blindly take the string after the |
@hudon yepp, reading quotes literally threw me off.
That would be great from a UX perspective too. Right now, trying to pass something nested, e.g. json, is quite a pain to do on one line (if you want any readability).
Given that I can source a file with the json defined within single quotes made me think it would be possible to declare variables on multilines with --env-file.
If nothing else, the error message for the first example I gave "docker: poorly formatted environment: variable '"test":"test"' is not a valid environment variable." could be more helpful if it contained a description of what's allowed. |
I stumbled over this issue today. My use case is trying to load a pair of PEM encoded RSA keys without exposing the keys via the process table with the It would be great if all three of these use cases could work without having to modify the file to make it compatible with the different parsing behaviors of the three. I suggest a simple double quoting like systemd does, with preservation of whitespace between the double quotes. As an example, I'd like this file to work with RSA_PUBLIC_KEY="-----BEGIN RSA PUBLIC KEY-----
...
-----END RSA PUBLIC KEY-----"
RSA_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----" |
I think it's fair to expect |
A pretty compelling use case for .env files is storing encryption keys outside of a code repository. Not being able to include new lines in values means being unable to store PEM encoded RSA keys without implementing some hackish workaround as described above. Moreover, this is inconsistent with the "environment:" section of a Docker compose YML file, where "\n" is actually replaced by a new line. I personally don't think that having a slighly better parser for env files is unnecessary complexity. |
If you are worried about backwards compatibility, a possible solution would be to add a new ".env2" file format which supports quotes and new lines. |
+1 we noticed an issue where docker |
+1 for --env-file handling quoted values; I need to handle some secrets containing newlines. |
+1 same here. We store private keys as env variables and this would greatly help us |
+1 same here. We store private keys as env variables and this would greatly help us too. |
+1 for --env-file handling quoted values; I need to handle some secrets containing newlines. |
It should be possible to use @duglin's quoter in the builder, maybe. On 20 Jan 2016, at 23:59, Marko Stipanov wrote:
|
It would be extremely helpful and common-sense to have Docker parse these files just like the shell would as depending on the scenario one will sometimes source the file, sometimes use --env-file +1 |
+1 Same use case as others: encryption keys being loaded, would prefer to be able to use --env-file for that. |
+1 Same usecase here |
+1 |
Spaces are problematic too..... docker: poorly formatted environment: variable 'KAFKA_HEAP_OPTS:'-Xms128M\ -Xmx256M'' has white spaces. |
@tiborvass Please follow up to the conversation. There have been +20 messages since you have closed the issue. |
@grizmin your error seems to indicate you're escaping values. The env-file format simply takes everything after
@gajus I suggest to open a proposal that adds this feature in a backward-compatible way, see for example #12997 (comment), or perhaps an approach that allows options to be passed. Such a proposal can be discussed (but no guarantees) However we should really guard against feature creep, and not try to replicate things that are already possible (e.g. options that are already possible by combining some shell commands). There's a real concern for adding a lot of complexity, and before we know it, we're re-inventing Bash |
+1 |
3 similar comments
+1 |
+1 |
+1 |
What's the point in continuing this "discussion" and speaking up, if we haven't had an official response since, with quite a lot of requests for this feature in 1,5 year time? |
@JeanMertz #12997 (comment), #12997 (comment). Changing the format for the current Note that if you have an environment variable set locally, you can already do this; export FOOBAR=hello
docker run -e FOOBAR busybox sh -c "echo \$FOOBAR"
hello (omitting |
Quick and dirty solution and possible temporal workaround is to replace string '\n' with actual newline symbol directly in code |
mesos 1.2.0 creates container via env_file marathon-acme for letsencrypte sert and marathon-lb for balancing i patched marathon-lb to replace \n in config to newline set newline as '\n' in mararthon LABELS for marathon-acme app |
+1 |
Here is another way of passing env vars to the container which is newline-safe: ENVS=`env | sed -n '/^[^\t]/s/=.*//p' | sed '/^$/d' | sed 's/^/-e /g' | tr '\n' ' '`
docker run $ENVS ...
|
+1 (this is really basic, and annoying.. this should be fixed) |
Same here. Please enable newline support. |
Wait... How did sharelatex get to run their example env-file while it is not supported? |
@louwers you linked to a Docker Compose file, not an env file as supported by the |
@hudon Yes thanks, I figured it out by now... 😅 |
👎 |
+1 |
+1, please implement it |
+1 |
I am locking the conversation on this one, because complaining and "+1"'s are not constructive, and will not get this change implemented. This repository is open source, and contributions are welcome; if this feature is important for you, invest time to get it moving. From my earlier comment #12997 (comment)
When writing such a proposal, be sure to describe what use cases it is resolving, and if other options are already possible; for example, docker services now support secrets ( |
Description of problem:
I have a
.env
file with variables likeTEST=hello\nworld
. When passed in withdocker run --env-file .env
, the process seeshello\nworld
, rather than:There seems to be no way for Docker to actually send a newline character with
--env-file
, only the two characters\
andn
.To reproduce:
expected output:
actual output:
docker version
:uname -a
: Darwin ip-192-168-1-138.ec2.internal 14.3.0 Darwin Kernel Version 14.3.0: Mon Mar 23 11:59:05 PDT 2015; root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64Environment details (AWS, VirtualBox, physical, etc.): boot2docker
docker info
:The text was updated successfully, but these errors were encountered: