compose icon indicating copy to clipboard operation
compose copied to clipboard

v2.10 expands .env file values

Open dimadeush opened this issue 3 years ago • 5 comments

Related to issue https://github.com/docker/compose/issues/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

dimadeush avatar Sep 04 '22 13:09 dimadeush

I had the exact same issue after updating to 2.10.2. Doubling the $ did the trick. See https://github.com/docker/compose/issues/9704#issuecomment-1202335152

knojector avatar Sep 06 '22 11:09 knojector

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

michaljusiega avatar Sep 07 '22 08:09 michaljusiega

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?

tyree731 avatar Sep 13 '22 19:09 tyree731

I have same problem in docker desktop 4.12

Are7even avatar Sep 16 '22 11:09 Are7even

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

Are7even avatar Sep 16 '22 11:09 Are7even

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.

milas avatar Sep 27 '22 17:09 milas