我正在拉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/