I am working with the following yaml and postgres_password_file, but it is not working. I have checked that the file inside container is correct and user/permissions of the file are correct. Postgres is creating postgres user but I cant find any password that fits that user, at the same time is not creating dbUser.
I don’t know what to check or what else to do. Do you have any ideas of why it is not working correctly?
Thanks in advance
yaml:
version: '2'
services:
db:
image: postgres:11
restart: always
user: postgres
environment:
- POSTGRES_PASSWORD_FILE=/run/secrets/pgpassfile
secrets:
- pgpassfile
secrets:
pgpassfile:
file: ./pgpassfile
pgpassfile own by postgres(999) inside and outside is:
*:5432:*:dbUser:password
postgres server log:
[+] Running 2/2
✔ Network scripts_default Created 0.1s
✔ Container scripts-db-1 Created 0.2s
Attaching to db-1
db-1 | The files belonging to this database system will be owned by user "postgres".
db-1 | This user must also own the server process.
db-1 |
db-1 | The database cluster will be initialized with locale "en_US.utf8".
db-1 | The default database encoding has accordingly been set to "UTF8".
db-1 | The default text search configuration will be set to "english".
db-1 |
db-1 | Data page checksums are disabled.
db-1 |
db-1 | fixing permissions on existing directory /var/lib/postgresql/data ... ok
db-1 | creating subdirectories ... ok
db-1 | selecting default max_connections ... 100
db-1 | selecting default shared_buffers ... 128MB
db-1 | selecting default timezone ... Etc/UTC
db-1 | selecting dynamic shared memory implementation ... posix
db-1 | creating configuration files ... ok
db-1 | running bootstrap script ... ok
db-1 | performing post-bootstrap initialization ... ok
db-1 |
db-1 | WARNING: enabling "trust" authentication for local connections
db-1 | You can change this by editing pg_hba.conf or using the option -A, or
db-1 | --auth-local and --auth-host, the next time you run initdb.
db-1 | syncing data to disk ... ok
db-1 |
db-1 | Success. You can now start the database server using:
db-1 |
db-1 | pg_ctl -D /var/lib/postgresql/data -l logfile start
db-1 |
db-1 | waiting for server to start....LOG: database system was shut down at 2024-02-09 13:52:25 UTC
db-1 | LOG: MultiXact member wraparound protections are now enabled
db-1 | LOG: database system is ready to accept connections
db-1 | LOG: autovacuum launcher started
db-1 | done
db-1 | server started
db-1 |
db-1 | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
db-1 |
db-1 | LOG: received fast shutdown request
db-1 | waiting for server to shut down...LOG: aborting any active transactions
db-1 | .LOG: autovacuum launcher shutting down
db-1 | LOG: shutting down
db-1 | LOG: database system is shut down
db-1 | done
db-1 | server stopped
db-1 |
db-1 | PostgreSQL init process complete; ready for start up.
db-1 |
db-1 | LOG: database system was shut down at 2024-02-09 13:52:27 UTC
db-1 | LOG: MultiXact member wraparound protections are now enabled
db-1 | LOG: autovacuum launcher started
db-1 | LOG: database system is ready to accept connections
2
Answers
POSTGRES_PASSWORD_FILE is not a way to set the .pgpass file, (which also wouldn’t make much sense since .pgpass is a client thing, not a server thing). It is an alternate way of setting POSTGRES_PASSWORD.
So what you did here was initialized the password for the ‘postgres’ user to be the string ‘*:5432:*:dbUser:password’
that is my postgre sample in docker-compose.yml.