postgresql - 如何在多阶段 Docker 容器中构建 Postgres jsonlog
问题描述
我有一个多级 Docker 容器,我在其中构建 jsonlog。
# Build stage
FROM postgres:11.5 AS build-env
ADD . /jsonlog
RUN apt-get update && apt-get install -y build-essential libkrb5-dev libssl-dev libpq-dev postgresql-server-dev-all
RUN cd /jsonlog && make install
# Used find to see where the output files are being installed
# RUN find / -name "*json*"
# Final stage
FROM postgres:11.5-alpine
COPY --from=build-env /usr/lib/postgresql/11/lib/bitcode/jsonlog/jsonlog.bc /usr/lib/postgresql/11/lib/bitcode/jsonlog/jsonlog.bc
COPY --from=build-env /usr/lib/postgresql/11/lib/bitcode/jsonlog.index.bc /usr/lib/postgresql/11/lib/bitcode/jsonlog.index.bc
COPY --from=build-env /usr/lib/postgresql/11/lib/jsonlog.so /usr/lib/postgresql/11/lib/jsonlog.so
docker build
好像还行 但是,当我执行 a 时docker run
,会出现此错误。
LOG: invalid value for parameter "log_destination": "jsonlog"
DETAIL: Unrecognized key word: "jsonlog".
FATAL: configuration file "/etc/postgresql/postgresql.conf" contains errors
jsonlog 代码来自我克隆的这个 repo, https://github.com/michaelpq/pg_plugins/tree/master/jsonlog 。我只将jsonlog
目录安装到构建容器中。
这postgresql.conf
是香草,除了这些线。
log_destination = 'jsonlog'
logging_collector = on
shared_preload_libraries = 'jsonlog'
做多阶段容器的原因是为了摆脱构建依赖并拥有更小的容器。我想运行postgres:11.5-alpine
,但postgres:11.5
图像也出现错误。
更新
我试着摆脱多阶段,只把所有东西都放在这样的 1 个容器中。
FROM postgres:11.5
ADD . /jsonlog
RUN apt-get update && apt-get install -y build-essential libkrb5-dev libssl-dev libpq-dev postgresql-server-dev-all
RUN cd /jsonlog && make install
但这会导致确切的Unrecognized key word: "jsonlog"
错误。
此外,我还尝试在 Postgres 9.5 容器中构建,并且发生了同样的事情。
解决方案
据我了解,您只需将 log_destination 保留为“stderr”,并且 jsonlog 插件会覆盖 PG 中的 log_hook,并且神奇地,日志开始以 JSON 格式输出。
因此,AFAIK 唯一需要的改变是:
shared_preload_libraries = 'jsonlog'
推荐阅读
- python - 在整列python中插入一个excel公式
- html - 计算出的宽度与指定的宽度有何不同?
- angular - Angular - 重构相对导入
- c# - 我是否使用了错误的 set/get 功能?
- extjs - ExtJs。如何将项目添加到网格列标题?(以现代为主题)
- r - 如何计算R中列联表的CI
- c++ - 是否可以使用带有模板非类型参数的#if 指令?(矢量多合一课)
- amazon-web-services - 缓存控制元数据不适用于 aws s3 中的文件
- php - 没有 Laravel Passport 的 Laravel API 返回 401(未授权)
- php - 在 Google Indexing API 上收到 403 错误