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

v2.10 expands .env file values #9806

Closed
dimadeush opened this issue Sep 4, 2022 · 6 comments
Closed

v2.10 expands .env file values #9806

dimadeush opened this issue Sep 4, 2022 · 6 comments

Comments

@dimadeush
Copy link

Related to issue #9704.
I have a php symfony framework with .env file and config params inside. There I have row:
CORS_ALLOW_ORIGIN=^https?://localhost(:[0-9]+)?$
when I'm trying to build using docker-compose I can see error: Invalid template: "^https?://localhost(:[0-9]+)?$"
docker-compose v2.10.2 (Linux Standalone binary), docker 2.10.17

@knojector
Copy link

I had the exact same issue after updating to 2.10.2. Doubling the $ did the trick. See #9704 (comment)

@michaljusiega
Copy link

michaljusiega commented Sep 7, 2022

I confirm this same issue related to .env file located in project directory with docker-compose.yml.

@tyree731
Copy link

I've confirmed here that adding double dollar signs, or single quotes, does prevent expansion of the variable... at the expense of modifying it. Some examples:

Without any escaping:

$ cat .env
FOO=$+0i
$ docker run -it --rm --env-file .env busybox env | grep FOO
FOO=$+0i
$ docker-compose ls
Invalid template: "$+0i"

With double dollar signs:

$ cat .env
FOO=$$+0i
$ docker run -it --rm --env-file .env busybox env | grep FOO
FOO=$$+0i
$ docker-compose ls
NAME                STATUS              CONFIG FILES

With single quotes:

$ cat .env
FOO='$+0i'
$ docker run -it --rm --env-file .env busybox env | grep FOO
FOO='$+0i'
$ docker-compose ls
NAME                STATUS              CONFIG FILES

Note that while this doesn't use docker compose for running busybox, the behavior is the same as I demonstrated above. What is the expected workaround here, for environment variables to escape the workaround characters in the service?

@Are7even
Copy link

Are7even commented Sep 16, 2022

I have same problem in docker desktop 4.12

@Are7even
Copy link

Related to issue #9704. I have a php symfony framework with .env file and config params inside. There I have row: CORS_ALLOW_ORIGIN=^https?://localhost(:[0-9]+)?$ when I'm trying to build using docker-compose I can see error: Invalid template: "^https?://localhost(:[0-9]+)?$" docker-compose v2.10.2 (Linux Standalone binary), docker 2.10.17

^http://localhost:[0-9]+ -- try this

@milas
Copy link
Contributor

milas commented Sep 27, 2022

This is fixed in v2.11.2 - the parser is now more flexible and won't error out in this situation anymore.

.env

UNQUOTED=^https?://localhost(:[0-9]+)?$
DOUBLE_QUOTED="^https?://localhost(:[0-9]+)?$"
SINGLE_QUOTED='^https?://localhost(:[0-9]+)?$'

Running env from a Compose service:

UNQUOTED=^https?://localhost(:[0-9]+)?$
DOUBLE_QUOTED=^https?://localhost(:[0-9]+)?$
SINGLE_QUOTED=^https?://localhost(:[0-9]+)?$

For situations like this, I would recommend using single quotes to prevent any unintentional interpolation - see #9879 for details.

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

6 participants