Closed r-xyz closed 7 months ago
I believe "Docker Secrets" is still a feature that was unfortunately only implemented for Swarm (and we should probably remove that section from our documentation). :disappointed:
Both the
docker-compose
anddocker stack
commands support defining secrets in a compose file.- https://docs.docker.com/engine/swarm/secrets/#defining-and-using-secrets-in-compose-files
Oh, I also wasn't aware that they both support it now.
service "postgres" refers to undefined secret postgres-password: invalid compose project
- either the
secrets
key in thepostgres
service is incorrect or the one defined in the globalsecrets
section needs to be changed- secrets: postgres-password + secrets: POSTGRES_PASSWORD
After swapping to the secret name, I indeed can reproduce. After looking at other things, I finally looked at the
env
and saw the problem:$ docker compose run postgres env ... POSTGRES_PASSWORD_FILE="/run/secrets/POSTGRES_PASSWORD" ... POSTGRES_USER="postgres" ... $ docker compose run postgres bash 2e9b336075bb:/# echo $POSTGRES_PASSWORD_FILE "/run/secrets/POSTGRES_PASSWORD"
So, don't put quotes here or they will be part of the literal string set in the env
- - POSTGRES_USER="postgres" - - POSTGRES_PASSWORD_FILE="/run/secrets/POSTGRES_PASSWORD" + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD_FILE=/run/secrets/POSTGRES_PASSWORD
This is fine too since these quotes are part of yaml syntax so don't become part of the value:
- "POSTGRES_PASSWORD_FILE=/run/secrets/POSTGRES_PASSWORD"
Hi all,
I am experiencing an issue trying to use Docker Secrets with latest postgres library (alpine), using Docker Compose.
From Official Page
Expected behaviour
Secret shall correctly be loaded from path in
POSTGRES_PASSWORD_FILE
(/run/secrets/POSTGRES_PASSWORD
).Current behaviour
$ docker compose up
fails withNonetheless, the file is present and contains the password:
Steps to reproduce
compose.yaml:
.secrets/POSTGRES_PASSWORD.txt: