How to customize the configuration file of the official PostgreSQL Docker image?

后端 未结 11 2059
时光取名叫无心
时光取名叫无心 2020-11-29 16:11

I\'m using the official Postgres Docker image trying to customize its configuration. For this purpose, I use the command sed to change max_connections

11条回答
  •  情深已故
    2020-11-29 16:33

    A fairly low-tech solution to this problem seems to be to declare the service (I'm using swarm on AWS and a yaml file) with your database files mounted to a persisted volume (here AWS EFS as denoted by the cloudstor:aws driver specification).

      version: '3.3'
      services:
        database:
          image: postgres:latest
          volumes:
            - postgresql:/var/lib/postgresql
            - postgresql_data:/var/lib/postgresql/data
        volumes:
           postgresql:
             driver: "cloudstor:aws" 
           postgresql_data:
             driver: "cloudstor:aws"
    
    1. The db comes up as initialized with the image default settings.
    2. You edit the conf settings inside the container, e.g if you want to increase the maximum number of concurrent connections that requires a restart
    3. stop the running container (or scale the service down to zero and then back to one)
    4. the swarm spawns a new container, which this time around picks up your persisted configuration settings and merrily applies them.

    A pleasant side-effect of persisting your configuration is that it also persists your databases (or was it the other way around) ;-)

提交回复
热议问题