首页 > 解决方案 > 替换 docker 容器中的 postgresql.conf

问题描述

我正在提取 postgres:12.0-alpine docker 映像来构建我的数据库。我的意图是替换容器中的 postgresql.conf 文件以反映我想要的更改(更改数据目录、修改备份选项等)。我正在尝试使用以下 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 "$@"

但是我收到一个 exec 错误,说 'custom_admin: not found on the 'exec "$@"' 行。我在这里想念什么?

标签: postgresqldockerunixdocker-entrypointpostgresql-12

解决方案


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

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是您的自定义配置文件。

有关 postgres 映像的更多信息,请参阅docker hub 页面


推荐阅读