Home > OS >  How can I properly escape the value of a .env variable that contains a dollar sign?
How can I properly escape the value of a .env variable that contains a dollar sign?

Time:02-03

In a .env file that I use in a docker-compose.yml file.

version: '3'
services:
  my_service:

    ...

    env_file:
      - src/.env

    ...

I've a variable set like this:

APIKEY_SALT=$foo$foo$foo/foo/foofoofoo

But docker-compose wrongly interprets that value:

WARN[0000] The "foo" variable is not set. Defaulting to a blank string.`

How can I escape it?

CodePudding user response:

wrap the variable in single quotes: APIKEY_SALT='$foo$foo$foo/foo/foofoofoo'

As mentioned here: https://deploy-preview-13474--docsdocker.netlify.app/compose/env-file/#syntax-rules

and here: https://github.com/docker/compose/issues/8607

  • Related