5

I have the following .env file:

# ENV
ENVIRONMENT=local
SITENAME=reo

I have the following docker-compose.yml (part of it) file:

volumes:
  ${SITENAME}-sync:
     external: true

I get the following error:

 volumes value '${SITENAME}-sync' does not match any of the regexes: u'^[a-zA-Z0-9._-]+$'

Is it possible to have a variable as a key in a Yaml file?

I noticed that: key: ${SITENAME} does work.

albertski
  • 2,428
  • 1
  • 25
  • 44

2 Answers2

3

Environment variables are not possible for keys in docker-compose.yml, only for values. See here

Michael K.
  • 1,738
  • 2
  • 17
  • 35
0

Since docker-compose doesn't support interpolation in keys, you'd need to add another level of indirection, e.g. use a templating tool like mustache or handlebars, and generate the docker-compose.yml file yourself from env vars.

Chris Johnson
  • 20,650
  • 6
  • 81
  • 80