Docker Community Forums

Share and learn in the Docker community.

Custom PostgreSQL with modified configuration files and database files stored on host's filesystem?

docker

(Mike Stoddart) #1

I want to create an image for PostgreSQL that will use the host’s filesystem for storing the database files.

I also need to adapt this image to override the default PGSQL configuration to enable accessing the database from any IPs. This is purely for a development environment so there are zero security worries or issues.

I know how to use the local filesystem and I know how to add a file from the host to the container. I don’t know how to do both of these things in the same image/container.

I tried using a Dockerfile:

FROM postgres:9.6.8
RUN echo "host all  all  0.0.0.0/0  trust" >> /var/lib/postgresql/data/pg_hba.conf
RUN echo "listen_addresses='*'" >> /var/lib/postgresql/data/postgresql.conf

With a compose file that includes:

version: "2"
services:
 db:
   image: "test-pgsql:latest"
   environment:
         - POSTGRES_USER=postgres
         - POSTGRES_PASSWORD=postgress
         - POSTGRES_DB=postgres
   ports:
         - "5433:5432"
   volumes:
         - /var/lib/postgresql/data:/var/lib/postgresql/data

This doesn’t work and I think it’s because the configuration files are modified inside the image but then the entire PGSQL folder is masked by the volume from the compose file.

Any suggestions for how to solve this would be appreciated. Thanks