Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

ERROR: Invalid interpolation format for "environment" option in service "time_service": "${Time.now}"

YAML:

--- version: '2' services:   time_service:     build: "."     environment:       TIME: "${Time.now}" 

How can I maintain the same string output as written, but avoid having the docker-compose interpret it as faulty string interpolation?

like image 649
Nathan Hanna Avatar asked Nov 15 '16 20:11

Nathan Hanna


People also ask

How do I escape Dockerfile?

The escape directive sets the character used to escape characters in a Dockerfile . If not specified, the default escape character is \ . The escape character is used both to escape characters in a line, and to escape a newline. This allows a Dockerfile instruction to span multiple lines.

What is Depends_on in Docker compose?

depends_on is a Docker Compose keyword to set the order in which services must start and stop. For example, suppose we want our web application, which we'll build as a web-app image, to start after our Postgres container.

What is in Docker compose command?

Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application's services. Then, with a single command, you create and start all the services from your configuration.


1 Answers

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

You are hitting the docker-compose variable substitution, 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.

like image 103
Anthon Avatar answered Oct 04 '22 13:10

Anthon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!