简体   繁体   中英

Mounting pgsql volume in Docker

I have a custom Dockerfile based on centos:latest that installs software I need to run the web framework I use. I want to extend this Dockerfile so that I can add PostgreSQL, the catch being that I want to change pgsql's default data location from /var/lib/pgsql to /var/www/data/pgsql , which is a filesystem-mounted volume. I'm not sure if it is possible to do this in the Dockerfile or if I need to run some script afterwards from within a container. Any help would be appreciated.

Ultimately you need to change data_directory in postgresql.conf. The default location for this in postgresql 9.5 is /etc/postgresql/9.5/main/postgresql.conf .

This might look like:

  1. Keep your own postgresql.conf file in version control, with data_directory = '/var/www/data/pgsql'
  2. In your Dockerfile, install postgresql
  3. In your Dockerfile, COPY postgresql.conf /etc/postgresql/9.5/main/postgresql.conf , which will move your altered postgresql.conf into the container, and replace the default postgresql.conf. This is assuming PG 9.5 default install location in the container.

Now when you run postgres, it should use your conf file with the /var/www/data/pgsql data directory.

edit: about moving data_directory

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM