postgresql - 在Docker容器中替换postgresql.conf

标签 postgresql docker unix docker-entrypoint postgresql-12

我正在拉postgres:12.0-alpine docker镜像来构建我的数据库。我的意图是替换容器中的postgresql.conf文件以反射(reflect)我想要的更改(更改数据目录,修改备份选项等)。我正在尝试以下 docker 文件

FROM postgres:12.0-alpine

# create the custom user 
RUN addgroup -S custom && adduser -S custom_admin -G custom

# create the appropriate directories 
ENV APP_HOME=/home/data 
ENV APP_SETTINGS=/var/lib/postgresql/data 
WORKDIR $APP_HOME

# copy entrypoint.sh 
COPY ./entrypoint.sh $APP_HOME/entrypoint.sh

# copy postgresql.conf 
COPY ./postgresql.conf $APP_HOME/postgresql.conf

RUN chmod +x /home/data/entrypoint.sh

# chown all the files to the app user 
RUN chown -R custom_admin:custom $APP_HOME 
RUN chown -R custom_admin:custom $APP_SETTINGS

# change to the app user 
USER custom_admin

# run entrypoint.sh 
ENTRYPOINT ["/home/data/entrypoint.sh"]

CMD ["custom_admin"]

我的entrypoint.sh看起来像
#!/bin/sh

rm /var/lib/postgresql/data/postgresql.conf
cp ./postgresql.conf /var/lib/postgresql/data/postgresql.conf

echo "replaced .conf file"

exec "$@"

但是我收到一个执行错误,说“custom_admin:在'exec“$ @”“行中找不到。我在这里想念什么?

最佳答案

为了提供自定义配置。请使用以下命令:

docker run -d --name some-postgres -v "$PWD/my-postgres.conf":/etc/postgresql/postgresql.conf postgres -c 'config_file=/etc/postgresql/postgresql.conf'

这里my-postgres.conf是您的自定义配置文件。

有关PostgreSQL图像的更多信息,请引用docker hub page

关于postgresql - 在Docker容器中替换postgresql.conf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59496338/

相关文章:

xml - Postgresql:如何更改 XML 列中属性的值?

docker - kubernetes,在一个容器中按容器共享卷

linux - "file"程序和fifo

c - C 语言简单程序,用于将字符串附加到目录中的所有文件

postgresql - 在 postgresql 函数中捕获选择查询返回值并使用它

database - 转义用户名中的破折号

postgresql - 最短路径在 pgrouting 中如何工作?

docker - 通过 docker-compose 将环境变量传递给 YAML

docker - Docker 教程上的连接被拒绝第 4 部分

unix - UNIX 上的文件系统如何查找文件?