docker-library / postgres

Docker Official Image packaging for Postgres
http://www.postgresql.org
MIT License
2.16k stars 1.13k forks source link

How can I override the postgresql.conf ? #1060

Closed ghevge closed 1 year ago

ghevge commented 1 year ago

How can I override the postgresql.conf ? In my Dockerfile I've tried the following:

COPY ./postgresql.conf /usr/local/share/postgresql/postgresql.conf
COPY ./postgresql.conf /etc/postgresql.conf
COPY ./postgresql.conf /etc/postgresql/postgresql.conf
COPY ./postgresql.conf /var/lib/postgresql/data/postgresql.conf
RUN echo 'tes = test' >> /var/lib/postgresql/data/postgresql.conf

Non of these approaches is changing the default configurations

I'm playing with postgres:15-alpine image.

Thanks

yosifkit commented 1 year ago

/var/lib/postgresql/data/ is a volume, so nothing can be saved there during image build, but that is the location for the config file generated by PostgreSQL's initdb and is used by default. It is generated from the /usr/local/share/postgresql/postgresql.conf.sample file (which we adjust for the images). You can replace that .sample and your custom config "sample" would be used to generate the .conf at first runtime. Or you can provide a full .conf anywhere (readable by postgres user) in the image and add -c 'config_file=/etc/postgresql/postgresql.conf' to a custom CMD

https://github.com/docker-library/docs/tree/df0fd9b92ebfaf3fee80c2319d4bea7455641216/postgres#database-configuration

# untested, but this *should* work
FROM postgres:15-alpine
COPY --chown postgres:postgres ./postgresql.conf /etc/postgresql.conf
CMD [ "-c", "config_file=/etc/postgresql/postgresql.conf" ]
ghevge commented 1 year ago

Thanks for clarifying this!

mdluo commented 3 months ago

/var/lib/postgresql/data/ is a volume, so nothing can be saved there during image build, but that is the location for the config file generated by PostgreSQL's initdb and is used by default. It is generated from the /usr/local/share/postgresql/postgresql.conf.sample file (which we adjust for the images). You can replace that .sample and your custom config "sample" would be used to generate the .conf at first runtime. Or you can provide a full .conf anywhere (readable by postgres user) in the image and add -c 'config_file=/etc/postgresql/postgresql.conf' to a custom CMD

https://github.com/docker-library/docs/tree/df0fd9b92ebfaf3fee80c2319d4bea7455641216/postgres#database-configuration

# untested, but this *should* work
FROM postgres:15-alpine
COPY --chown postgres:postgres ./postgresql.conf /etc/postgresql.conf
CMD [ "-c", "config_file=/etc/postgresql/postgresql.conf" ]

Minor correction:

COPY --chown=postgres:postgres ./postgresql.conf /etc/postgresql.conf
CMD [ "-c", "config_file=/etc/postgresql.conf" ]