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

后端 未结 11 1980
时光取名叫无心
时光取名叫无心 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:27

    You can put your custom postgresql.conf in a temporary file inside the container, and overwrite the default configuration at runtime.

    To do that :

    • Copy your custom postgresql.conf inside your container
    • Copy the updateConfig.sh file in /docker-entrypoint-initdb.d/

    Dockerfile

    FROM postgres:9.6
    
    COPY postgresql.conf      /tmp/postgresql.conf
    COPY updateConfig.sh      /docker-entrypoint-initdb.d/_updateConfig.sh
    

    updateConfig.sh

    #!/usr/bin/env bash
    
    cat /tmp/postgresql.conf > /var/lib/postgresql/data/postgresql.conf
    

    At runtime, the container will execute the script inside /docker-entrypoint-initdb.d/ and overwrite the default configuration with yout custom one.

提交回复
热议问题