Is there any difference between these two configs:
Config 1:
...
environment:
- POSTGRES_NAME='postgres'
- POSTGRES_USER='postgres'
- POSTGRES_PASSWORD='postgres'
- POSTGRES_PORT='5432'
Config 2:
...
environment:
- POSTGRES_NAME=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_PORT=5432
Because, when I try to docker-compose up
with Config 1 it throws an error (django.db.utils.OperationalError: FATAL: password authentication failed for user "postgres"
), and it works fine with Config 2. What is wrong with docker-compose.yml?
2
Answers
…
environment:
In a YAML scalar, the entire string can be quoted, but quotes inside a string are interpreted literally as quotes. (This is a different behavior than, say, the Bourne shell.)
So in this fragment:
The value of
environment:
is a YAML list. Each list item contains a YAML string. The string is the literal stringPOSTGRES_NAME='postgres'
, including the single quotes. Compose then splits this on the equals sign and sets the variablePOSTGRES_NAME
to the value'postgres'
, including the single quotes.There’s two ways to work around this. One is to not quote anything; even if there are "special characters" after the equals sign, it will still be interpreted as part of the value.
A second way is to use the alternate syntax for
ENVIRONMENT
that’s a YAML mapping instead of a list of strings. You’d then use YAML (not shell) quoting for the value part (and the key part if you’d like).