-
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
Variables containing special characters coming from env file are not preserved #8607
Comments
Unfortunately the dotEnv file format is a de facto standard with no established specification. On Compose V2 we rely on godotenv library which has been designed to align with Ruby's implementation of dotEnv support, but has obvious differences with the python one. We can't be 100% compatible with the Python implementation (until we design our own dotEnv parser for this single reason) Basically, we recommend you wrap any value that might be ambiguous with single quotes. |
Proposed update to docs to clarify differences between v1 and v2 regarding dotEnv file format: https://deploy-preview-13474--docsdocker.netlify.app/compose/env-file/#syntax-rules |
Thank you! It is a lot clearer like that. I noticed a small typo:
|
As for the differences I noticed with ruby's dotenv, I filed an issue in the godotenv repo: joho/godotenv#155 |
I hit this as well and was very confused when all of my traefik basic auth rules started not applying. Can this be noted somewhere more prominently, e.g. on the releases or readme with other differences? This seems like a significant change which is likely to hit people who are using things like basic auth (where the username/salt/etc are |
I was beating myself senseless with a similar issue because I had a basic auth entry in my dotenv for Traefik but it just kept giving me a 403.
So using the following was enough BASIC_AUTH_USER='test'
BASIC_AUTH_PWD='$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/' |
In such cases, the first published version of a product that uses the format is the specification. Any later versions must adhere to the interpretation of the first version. This is unfortunate for the developer, but should teach them not to rely on unspecified behavior. |
Apparently, docker-compose V1 already supported single quotes around the values, so this bullet point in the old docs was already wrong:
If the breaking changes cannot be avoided, at least the docs should mention that single-quoting the value will block variable substitution and is compatible with both V1 and V2. |
The behavior with single quotes around the value in docker compose V1 is actually platform-dependent:
If anything changes with respect to quotes or other escape character processing when reading .env files in compose V2, then this needs to be announced loudly (and correctly) in the migration docs. https://github.com/compose-spec/compose-spec/blob/master/spec.md sounds like the behavior of compose V2 matches V1 on Linux. That would be great! |
Didn't know, that's bad :'( https://github.com/compose-spec/compose-spec/blob/master/spec.md#env_file-format is definitively wrong regarding quotes, this is not how Compose v2 behaves AFAICT, and this is not relevant from a yaml syntax point of view. Need to be fixed (cc @glours @ulyssessouza) |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically closed because it had not recent activity during the stale period. |
Description of the issue
Variables containing special characters coming from env file are not preserved
Context information (for bug reports)
docker compose ...
docker-compose ...
Output of
docker(-)compose version
(Also, Output of
docker-compose-v1 version
)Output of
docker version
Output of
docker-compose config
(Make sure to add the relevant
-f
and other flags)Steps to reproduce the issue
.env
file with the following contentObserved result
Some parts of the environment variables are missing:
Indeed,
docker-compose up --build
producesExpected result
As the documentation states
So I expect the original values to be preserved, including all "special" characters (
' " $0 $_
...).As a consquence, from what I understand,
docker-compose up --build
should produce:Additional information
For information, the v1 version of docker-compose produces (
docker-compose-v1 up --build
):and
docker-compose-v1 config
:Which is not exactly the expected result either (quotes and leading spaces are NOT being preserved), but seems more reasonable when it comes to dollar signs.
Documentation issue
Whether it is chosen to preserve or not quotation marks or special characters (including spaces), I think it would be important that the documentation reflects the actual behaviour.
The text was updated successfully, but these errors were encountered: