1

I try to add environment variable that has regex value

version: "2.3"
services:
    ...
  php:
    ...
    environment:
      - "CORS_ALLOW_ORIGIN=^https?://localhost(:[0-9]+)?$"

when run docker-compose up

it gives me that error: ERROR: Invalid interpolation format for "environment" option in service "php": "CORS_ALLOW_ORIGIN=^https?://localhost(:[0-9]+)?$"

I have played around and removed $, it works fine but want to keep it.

Any idea?

yakob abada
  • 1,101
  • 14
  • 20
  • Possible duplicate of [How can I escape a $ dollar sign in a docker compose file?](https://stackoverflow.com/questions/40619582/how-can-i-escape-a-dollar-sign-in-a-docker-compose-file) – kenorb Feb 16 '19 at 13:47

2 Answers2

0

It tries to expand your dollar sign. Try using \$ instead of $ or take value in single quotes which prevent macro expansion.

grapes
  • 8,185
  • 1
  • 19
  • 31
0

Use $$ to escape the dollar ($) symbols.

version: "2.3"
services:
    ...
  php:
    ...
    environment:
      - "CORS_ALLOW_ORIGIN='^https?://localhost(:[0-9]+)?$$'

See variable substitution in the docker-compose doc (v2)

GiDo
  • 1,280
  • 12
  • 23