I am trying to configure the postgres docker image to run as part of the compose setup and have hit an unexpected problem with it. I suspect it is somehow related to the image itself and some internal details about it as it's extremely minimalistic:
services:
db_master:
image: postgres:16.1-bullseye
user: postgres
restart: on-failure:3
hostname: postgres_master
ports:
- 0.0.0.0:25432:5432
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DB: postgres
PGHOSTADDR: 0.0.0.0
POSTGRES_NAME: test-postgres
POSTGRES_ALLOW_EMPTY_PASSWORD: 1
POSTGRES_HOST_AUTH_METHOD: "trust"
POSTGRES_INITDB_ARGS: "--log_min_messages=DEBUG1 --archive_mode=on --archive_command='test ! -f /tmp/db_backup/%f && cp %p /tmp/db_backup/%f'"
which produces an error:
db_master_1 | initdb: unrecognized option '--log_min_messages=DEBUG1'
I have also tried to use a list for environment:
db_backup:
image: postgres_tm:latest
user: postgres
restart: unless-stopped
hostname: postgres_backup
ports:
- 0.0.0.0:35432:5432
environment:
- POSTGRES_PASSWORD=postgres
- POSTGRES_USER=postgres
- POSTGRES_DB=postgres
- PGHOSTADDR=0.0.0.0
- POSTGRES_NAME=backup-postgres
- POSTGRES_ALLOW_EMPTY_PASSWORD=1
- POSTGRES_HOST_AUTH_METHOD="trust"
- POSTGRES_INITDB_ARGS="--log_min_messages=DEBUG1 --archive_mode=on --archive_command='test ! -f /tmp/db_backup/%f && cp %p /tmp/db_backup/%f'"
which gives a slightly different error, suggesting the entire arg is packed into extra quotations and stored as such:
db_backup_1 | initdb: unrecognized option '--log_min_messages=DEBUG1 --archive_mode=on --archive_command='test ! -f /tmp/db_backup/%f && cp %p /tmp/db_backup/%f''
db_backup_1 | initdb: hint: Try "initdb --help" for more information.
I even tried using an .env file, but the outcome is the same every time.
I must say it's very confusing ass I've seen some complains about compose handling of multiargs when they are stored as environmental variable. I tried using a single argument only but it still complained about any type of argument, be it debug or archive_mode=on
my host environment details:
- docker-compose version 1.25.0, build unknown
- Docker version 24.0.7, build afdd53b
EDIT
After digging into the docker entrypoint script I can see that the initdb only initialises the database, but does not pass arguments used by postgres itself. I would really prefer to avoid having to bake custom made config file into the image and would prefer more docker-friendly setup that's easy to orchestrate and scale, so suggestions are very welcome and appreciated