postgres: Unable to replace postgresql.conf
Using the dockerfile:
FROM postgres:9.3
COPY postgresql.conf /var/lib/postgresql/data/postgresql.conf
(the content of postgresql.conf doesn’t matter - at the moment it is a duplicate of what would be there when the image starts)
I can build the image, but when I run it I get the error:
postgres_1 | initdb: directory "/var/lib/postgresql/data" exists but is not empty
postgres_1 | If you want to create a new database system, either remove or empty
postgres_1 | the directory "/var/lib/postgresql/data" or run initdb
postgres_1 | with an argument other than "/var/lib/postgresql/data".
Why can’t I just replace the config file in this way?
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 10
- Comments: 21 (5 by maintainers)
Commits related to this issue
- Issue #105: Update include_if_exists entry in configuration This allows the default settings file to be supplemented with additional settings. It is possible to replace all settings in this way, so a... — committed to matthewfranglen/postgres by matthewfranglen 8 years ago
- Issue #105: Add include_if_exists entry in configuration This allows the default settings file to be supplemented with additional settings. It is possible to replace all settings in this way, so a co... — committed to matthewfranglen/postgres by matthewfranglen 8 years ago
- postgresql.conf is now used by Postgres - solution found in https://github.com/docker-library/postgres/issues/105 — committed to shopsys/shopsys by TomasLudvik 5 years ago
- postgresql.conf is now used by Postgres - solution found in https://github.com/docker-library/postgres/issues/105 — committed to shopsys/shopsys by TomasLudvik 5 years ago
- postgresql.conf is now used by Postgres - solution found in https://github.com/docker-library/postgres/issues/105 — committed to shopsys/shopsys by TomasLudvik 5 years ago
- postgresql.conf is now used by Postgres - solution found in https://github.com/docker-library/postgres/issues/105 — committed to shopsys/project-base by TomasLudvik 5 years ago
- postgresql.conf is now used by Postgres - solution found in https://github.com/docker-library/postgres/issues/105 — committed to shopsys/shopsys by TomasLudvik 5 years ago
- postgresql.conf is now used by Postgres - solution found in https://github.com/docker-library/postgres/issues/105 — committed to shopsys/shopsys by TomasLudvik 5 years ago
- postgresql.conf is now used by Postgres (#946) - solution was found in https://github.com/docker-library/postgres/issues/105 — committed to shopsys/shopsys by TomasLudvik 5 years ago
- postgresql.conf is now used by Postgres (#946) - solution was found in https://github.com/docker-library/postgres/issues/105 — committed to shopsys/project-base by TomasLudvik 5 years ago
FYI, you can inject
postgresql.conf
file using Docker volume +config_file
postgres option:Originally posted in StackOverflow question: http://stackoverflow.com/a/40598124/385548
For anyone finding this issue through a search, I ended up doing this:
Where set-config.sh is:
I do hope that this issue is fixed though. One fix that would be backwards compatible with existing images would be for the
docker-entrypoint.sh
script to look for a configuration file in a specific place and copy it into the correct place if the PGDATA folder has not been initialized.@yosifkit I figured out the problem though. I set PGDATA to the same location where I put my custom postgres.conf. So inidb doesn’t like it when it encounter a non-empty folder
Move PGDATA 1 level more deep should work
+1 for this… For example I would like to turn on logging (log_statement “all”) for dev purposes by overriding default config… FWIW i’ve been using https://github.com/sameersbn/docker-postgresql instead until this (hopefully) lands
So it does read the
.sample
file and then apply some mostlyLANG
/locale
based changes. The listen address change is us in the entrypoint.But that means a user can just mount their config to
/usr/share/postgresql/9.4/postgresql.conf.sample
and it will be sourced into the real config file on database creation.An alternative way would be to use a Dockerfile:
That is true. However that produces a greater variance between the supported versions as
include_dir
is not available for 9.1 or 9.2 which are both still supported.You could use
include_dir
in the configuration file you use to supplement the settings.I guess the real problem is that the postgresql.conf file is in the same folder as the database files.
When installing postgres onto a system using apt-get, the configuration files end up in
/etc/postgresql/VERSION/main/
and the database files end up in/var/lib/postgresql/VERSION/main/
. If this setup was replicated in this docker image then there would be no problem with directly replacing the configuration file without also manually creating all of the database directories.If I compare the behaviour of this image to mysql I can see that mysql does not alter itself in this way. MySQL allows you to overwrite the
/etc/mysql/my.cnf
, or supplement it using a file in/etc/mysql/conf.d
. Both of these options make it very easy to do some light customization of the image for a specific use case.Given that this image behaves differently from the default postgres behaviour I have to ask why this was done. I think that it should be possible to overwrite the postgresql.conf file by merely mounting it into the container without having to write a script which is a glorified
mv
.