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

Inconsistent handling of quoted variables in .env between Compose v1 and v2 #8740

Closed
jpetazzo opened this issue Oct 4, 2021 · 5 comments
Closed
Labels

Comments

@jpetazzo
Copy link

jpetazzo commented Oct 4, 2021

Brief description:

Quotes in .env files aren't handled the same way between Compose v1 and Compose v2.

Specifically, with Compose v2, variables with spaces must be quoted, otherwise, they get truncated.
In Compose v1, in remember that in one case, I had to remove the quotes, because they would show up in the variable (but I can't reproduce that issue right now so it might be specific to some older versions of Compose v1?)

Steps to reproduce the issue:

Create the following files:

mkdir -p /tmp/compose-v2-envquotes
cd /tmp/compose-v2-envquotes

cat >docker-compose.yml <<EOF
version: "3"

services:
  env:
    image: alpine
    environment:
    - WITHQUOTES
    - WITHOUTQUOTES
    command: env
EOF

cat >.env <<EOF
WITHQUOTES="With quotes"
WITHOUTQUOTES=Without quotes
EOF

Then docker-compose up.

Describe the results you received:

With Compose v1, both variables are fully present:

...
env_1  | WITHQUOTES=With quotes
env_1  | WITHOUTQUOTES=Without quotes
...

With Compose v2, the variable without quotes is truncated:

...
compose-v2-envquotes-env-1  | WITHOUTQUOTES=Without
compose-v2-envquotes-env-1  | WITHQUOTES=With quotes
...

Describe the results you expected:

Identical result with both versions of Compose.

Output of docker compose version:

docker-compose version 1.29.2, build unknown
docker-py version: 5.0.2
CPython version: 3.9.7
OpenSSL version: OpenSSL 1.1.1l  24 Aug 2021
Docker Compose version v2.0.1

Similar or related issues:

This could be related to #8626 (which is also about an env issue) but it might also be a different bug, so I'm opening a separate issue.

@Shikachuu
Copy link

Shikachuu commented Oct 6, 2021

@ndeloof
This issue and issue #8741 are probably a godotenv problem like #8626.
Seems like this godotenv PR will fix this bug aswell.

@TheTerrasque
Copy link

I would like to point out that this goes directly against the environment file spec at https://docs.docker.com/compose/env-file/

One of the syntax rules mentioned there is:

  • There is no special handling of quotation marks. This means that they are part of the VAL.

@ndeloof
Copy link
Contributor

ndeloof commented Oct 6, 2021

Yes, doc need to be updated for V2, see https://github.com/docker/docker.github.io/pull/13474/files#diff-8edc9c85338bc8e7c7a80ef3a0a01ec54cfad9e2ac61824e40c42c66604c3355

@stale
Copy link

stale bot commented Apr 16, 2022

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.

@stale stale bot added the stale label Apr 16, 2022
@stale
Copy link

stale bot commented Apr 28, 2022

This issue has been automatically closed because it had not recent activity during the stale period.

@stale stale bot closed this as completed Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants