首页 > 解决方案 > 如何使用 HLL 扩展构建 Postgres:11 的图像?

问题描述

我想制作一个 Dockerfile 来构建 Postgres:11 的映像,其中已经安装了postgresql-hll 扩展。我没有使用 Docker 的经验,所以我不知道要遵循正确安装此扩展的说明。

标签: postgresqldocker

解决方案


为此,您需要:

  1. 克隆 git 存储库:
git clone https://github.com/citusdata/postgresql-hll.git
  1. 创建一个名为Dockerfile(与步骤 1 中创建的文件夹 postgresql-hll 处于同一级别)的文件,其内容为:
ARG psversion=11

FROM postgres:$psversion

COPY postgresql-hll /postgresql-hll
RUN apt-get update -y && apt-get install -y postgresql-server-dev-${PG_MAJOR} make gcc g++

WORKDIR /postgresql-hll

RUN PG_CONFIG=/usr/bin/pg_config make
RUN PG_CONFIG=/usr/bin/pg_config make install

RUN echo "shared_preload_libraries = 'hll'" >> /usr/share/postgresql/postgresql.conf.sample

COPY create_extension.sql /docker-entrypoint-initdb.d/
  1. 创建一个create_extension.sql与 Dockerfile 同级的文件,内容如下:
CREATE EXTENSION hll;
  1. 建立你的形象:
# build for POSTGRES 11
docker build -t hll:1.0 --build-arg psversion=11 .

# build for POSTGRES 9.6
docker build -t hll:1.0 --build-arg psversion=9 .

注意: POSTGRES 9.6 的版本在尝试加载库时会出错。它在这里是为了完整性,也许有人可以为修复它做出贡献。

  1. 基于这个镜像运行一个容器
docker run -d --name hll hll:1.0
  1. 在新创建的容器中打开一个 shell:
docker exec -ti hll bash
  1. 在容器内运行:
su postgres
psql
\dx

输出应显示已安装的 hll 扩展。


推荐阅读