postgresql - 替换 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 "$@"' 行。我在这里想念什么?
解决方案
为了提供自定义配置。请使用以下命令:
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 页面。
推荐阅读
- javascript - 如何在选项卡切换中激活选项卡面板的第二项
- filter - Tableau - 如何将筛选值包含到操作中并筛选目标工作表
- gitlab-ci - 在 Gitlab CI 中,当我推送标签时取消 master 上的管道
- actions-on-google - Google Assistant Basic 卡片正文是可点击的
- javascript - 如何使用 JavaScript 读取跨域 CSS 规则?
- python - 使用 3d-lego 绘图可视化 numpy 数组
- next.js - NextJs 重定向错误
- javascript - Nodejs/Javascript 输出写入所有文件而不是单个文件
- javascript - 自定义钩子在点击时不触发
- snowflake-cloud-data-platform - 如何在 Snowflake SQL 中检索当前的 GMT 日期和时间