如何在多阶段Docker容器中构建Postgres jsonlog [英] How to build Postgres jsonlog in multi-stage Docker container

查看:112
本文介绍了如何在多阶段Docker容器中构建Postgres jsonlog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于构建jsonlog的多阶段Docker容器。

I have a multi-stage Docker container where I build 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 似乎还可以。但是,当我执行 docker run 时,会出现此错误。

The docker build seems to be okay. However, when I do a docker run, I get this error.

LOG:  invalid value for parameter "log_destination": "jsonlog"
DETAIL:  Unrecognized key word: "jsonlog".
FATAL:  configuration file "/etc/postgresql/postgresql.conf" contains errors

jsonlog代码来自此仓库 https://github.com/michaelpq/pg_plugins/tree / master / jsonlog ,是我克隆的。我只将 jsonlog 目录安装到构建容器中。

The jsonlog code comes from this repo, https://github.com/michaelpq/pg_plugins/tree/master/jsonlog, which I cloned. I mount just the jsonlog directory into the build container.

postgresql.conf 是香草的,除了这些行。

The postgresql.conf is vanilla, except for these lines.

log_destination = 'jsonlog'
logging_collector = on
shared_preload_libraries = 'jsonlog'

做多阶段容器的原因是摆脱了构建依赖关系,并拥有一个较小的容器。我想运行 postgres:11.5-alpine ,但是 postgres:11.5 图像也会出错。

The reason for doing a multi-stage container is to get rid of build dependencies and have a smaller container. I'd like to run postgres:11.5-alpine, but I also get errors with the postgres:11.5 image.

更新

我尝试摆脱多阶段操作并保持

I tried getting rid of the multi-stage and just keeping everything in 1 container like this.

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

但这导致确切的无法识别的关键字: jsonlog 错误。

此外,我也尝试在Postgres 9.5容器中进行构建,并且发生了相同的事情。

Also, also, I tried building in a Postgres 9.5 container and the same thing happens.

推荐答案

据我了解,您只是将log_destination保留为'stderr',而jsonlog插件会覆盖PG中的log_hook,并且神奇地,日志开始以JSON格式输出。

It's my understanding that you simply leave log_destination as 'stderr' and the jsonlog plugin overrides the log_hook in PG and, magically, logs start coming out in JSON format.

因此,唯一需要更改的AFAIK是:

So the only change needed, AFAIK, is:

shared_preload_libraries ='jsonlog'

shared_preload_libraries = 'jsonlog'

这篇关于如何在多阶段Docker容器中构建Postgres jsonlog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆