This container is rather handy but I've found it more difficult than I expected to apply a non-default configuration. Specifically I needed to install SSL certificates and keys, apply some postgresql.conf entries and modify pg_hba.conf.
To do so I had to create a setup script in /docker-entrypoint-initdb.d/ to overwrite pg_hba.conf, append to postgresql.conf and copy the SSL certs in from a bind mounted volume. Originally I actually went further and made a derived container that copied these things in before I realised I could just bind mount.
I suggest:
- document that bind-mounting
/docker-entrypoint-initdb.d/ is a good way to run scripts and load configuration;
- Special case a
/docker-entrypoint-initdb.d/copy-files.d/ directory. When present, copy everything in copy-files.d to the new datadir (recursively, preserving mode and changing ownership to container user). So you can add an include_dir etc.
- Special case a
/docker-entrypoint-initdb.d/append-files.d/ directory. When present, append everything in append-files.d to the new datadir with the same filename, creating it if it doesn't exist.
- Auto-append
include_dir 'postgresql.conf.d' to the generated postgresql.conf. Document that any config file snippet placed in /docker-entrypoint-initdb.d/copy-files.d/postgresql.conf.d/ will be copied to the datadir and loaded as part of PostgreSQL's configuration. Or alternately just special case postgresql.conf.d in the docker-entrypoint-initdb.d and auto-enable include_dir if it's present.
- Make it more obvious in the docs that scripts in
/docker-entrypoint-initdb.d/ run as the postgres user.
This container is rather handy but I've found it more difficult than I expected to apply a non-default configuration. Specifically I needed to install SSL certificates and keys, apply some
postgresql.confentries and modifypg_hba.conf.To do so I had to create a setup script in
/docker-entrypoint-initdb.d/to overwritepg_hba.conf, append topostgresql.confand copy the SSL certs in from a bind mounted volume. Originally I actually went further and made a derived container that copied these things in before I realised I could just bind mount.I suggest:
/docker-entrypoint-initdb.d/is a good way to run scripts and load configuration;/docker-entrypoint-initdb.d/copy-files.d/directory. When present, copy everything incopy-files.dto the new datadir (recursively, preserving mode and changing ownership to container user). So you can add an include_dir etc./docker-entrypoint-initdb.d/append-files.d/directory. When present, append everything inappend-files.dto the new datadir with the same filename, creating it if it doesn't exist.include_dir 'postgresql.conf.d'to the generatedpostgresql.conf. Document that any config file snippet placed in/docker-entrypoint-initdb.d/copy-files.d/postgresql.conf.d/will be copied to the datadir and loaded as part of PostgreSQL's configuration. Or alternately just special casepostgresql.conf.din thedocker-entrypoint-initdb.dand auto-enableinclude_dirif it's present./docker-entrypoint-initdb.d/run as the postgres user.