Skip to content

suggestion: add a default include_dir configuration #835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mathroc opened this issue Apr 15, 2021 · 7 comments
Open

suggestion: add a default include_dir configuration #835

mathroc opened this issue Apr 15, 2021 · 7 comments
Labels
Request Request for image modification or feature

Comments

@mathroc
Copy link

mathroc commented Apr 15, 2021

Hi,

I find it harder than it should be to customize postgresql.conf:

  • usually PGDATA is bind mounted so it’s not always easy to add a file in there at the right time (or replace a file)
  • there’s options with /docker-entrypoint-initdb.d scripts but those are executed only when the database does not exists

so I suggest to add an include_dir configuration in the default postgresql.conf

in the Dockerfile, where listen_addresses is added, something along mkdir /docker-postgres-conf.d/ && echo 'include_dir=/docker-postgres-conf.d/' >> /usr/share/postgresql/postgresql.conf.sample

I believe this would be really useful, comes with no BC break and low maintenance

what do you think ?

(might be related to #581)

@wglambert wglambert added the Request Request for image modification or feature label Apr 15, 2021
@marko-asplund
Copy link

Sometimes it can be necessary to be able to customize server config within the image instead of overriding via command line arguments to docker run, so +1 for this.

What do you think @wglambert ?

@marko-asplund
Copy link

Actually, would also be great if it would be possible to interpolate container start-up time environment variable values in config files. This would be useful e.g. in configuring cron.database_name parameter value for the pg_cron extension.

@yosifkit
Copy link
Member

yosifkit commented Jun 9, 2021

Using your suggestion, it is not that hard to extend the image for your own needs. Unfortunately, I don't think this is something we want to add to the image right now.

FROM postgres:13
RUN set eux; \
	confdir='/docker-postgres-conf.d/'; \
	mkdir -p "$confdir"; \
	chown postgres:postgres "$confdir"; \
	echo "include_dir = '$confdir'" >> /usr/share/postgresql/postgresql.conf.sample
$ docker build -t pg .
Sending build context to Docker daemon  11.26kB
Step 1/2 : FROM postgres:13
 ---> 293e4ed402ba
Step 2/2 : RUN set eux; 	confdir='/docker-postgres-conf.d/'; 	mkdir "$confdir"; 	chown postgres:postgres "$confdir"; 	echo "include_dir = '$confdir'" >> /usr/share/postgresql/postgresql.conf.sample
 ---> Running in 01feb0757294
Removing intermediate container 01feb0757294
 ---> c9083ff81afd
Successfully built c9083ff81afd
Successfully tagged pg:latest
$ cat extra.conf
shared_buffers=256MB
$ docker run -it --rm -e POSTGRES_PASSWORD=12345 --name pg-test -v "$PWD/extra.conf":/docker-postgres-conf.d/extra.conf pg
$ # check via another terminal and shared_buffers is correctly changed from the default

Conf files mounted this way or otherwise placed in the configuration directory would need to have proper permissions for the postgres user to read it.

@mathroc
Copy link
Author

mathroc commented Jun 9, 2021

thx @yosifkit ! It’s indeed not too hard. Especially if we’re already build a custom image (eg: to install 3rd party extensions)

Still, I don’t understand why it should not be included in the base image, is it to keep as close as possible to the default Postgres configuration ? Or is it not useful enough ?

If you have a bit of time to spare, I would be interested in reading your point of view on the subject

I’m just asking out of curiosity, feel free to ignore this and close the issue if it’s not useful to keep this issue around. I won’t be offended !

And if you have time to waste, here is the thought process that led me to open this issue/suggestion :

For most project the default Postgres image is enough, and I can make it work by changing the configuration with command line arguments, but it’s not the nicest when you want to read / edit or look at configuration changes over time (because it’s - in my case - included in the docker-compose.yml file which should not, imho, be the place where I configure Postgres. The alternative is, as you mentioned, to build a custom image, either adding an include_dir in the default configuration file and mounting the configuration as a volume (or docker config) or adding the whole configuration into the image. Either way, it requires building and tagging a new image and probably pushing it to a registry. It’s not a huge task, but it’s tedious, and if you don’t already build custom images as part of your process it’s even more intimidating. I’m not a maintainer of widely use docker images, so I can definitely have missed something, but I thought this change comes with very little costs.

@thieltec

This comment was marked as duplicate.

@oshmyrko

This comment was marked as off-topic.

@arist0v
Copy link

arist0v commented May 21, 2024

i would really like to have an option to specify an include_dirs,

to achieve it i:

  • created a custom entrypoint script
  • called the default one
  • wait a little time then stop the service
  • edit the .conf to add the include dir
  • restart the service
#!/bin/bash
set -e

# Call the original entrypoint script to set up the environment
docker-entrypoint.sh postgres &

# Wait for the PostgreSQL server to be initialized and the postgresql.conf file to be generated
sleep 10

# Modify the postgresql.conf file
echo "include_dir = '/etc/my_folder/pgconf/'" >> /var/lib/postgresql/data/postgresql.conf

# Stop the PostgreSQL server that was started by the original entrypoint script
pg_ctl -D "$PGDATA" -m fast -w stop

# Now start the PostgreSQL server again with the modified configuration
exec postgres

it shouldn't be too hard to set in the entrypoint a verification if an include_dirs env var is set, and if path exist enable the include_dirs conf with this path in the original .conf before starting it, base use will still be able to use the current image as it, and advanced use will be able to use it as a base image and include custom .conf to be added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Request Request for image modification or feature
Projects
None yet
Development

No branches or pull requests

7 participants