How can I escape a $ dollar sign in a docker compose file?

前端 未结 2 1707
生来不讨喜
生来不讨喜 2020-11-29 02:54

I have a YAML scalar that is throwing the following error when I try to evaluate my docker-compose.yml file:

ERROR: Invalid interpolation

相关标签:
2条回答
  • 2020-11-29 03:40

    Found the answer by copying the suggestion for % characters in this post

    It requires a double dollar sign $$.

    So I needed "$${Time.now}", which evaluates to "${Time.now}"

    0 讨论(0)
  • 2020-11-29 03:43

    You can use a $$ (double-dollar sign) when your configuration needs a literal dollar sign.

    You are hitting the docker-compose variable substition, which is well documented here:

    Both $VARIABLE and ${VARIABLE} syntax are supported. Extended shell-style features, such as ${VARIABLE-default} and ${VARIABLE/foo/bar}, are not supported.

    You can use a $$ (double-dollar sign) when your configuration needs a literal dollar sign. This also prevents Compose from interpolating a value, so a $$ allows you to refer to environment variables that you don’t want processed by Compose.

    docker-compose is written in Python, as you see on github, the doubling mechanism to get the original meaning of special characters can be found in many programs, I needed to use this myself, while programming, as far back in 1984.

    0 讨论(0)
提交回复
热议问题