postgresql - 如何使用 HLL 扩展构建 Postgres:11 的图像?
问题描述
我想制作一个 Dockerfile 来构建 Postgres:11 的映像,其中已经安装了postgresql-hll 扩展。我没有使用 Docker 的经验,所以我不知道要遵循正确安装此扩展的说明。
解决方案
为此,您需要:
- 克隆 git 存储库:
git clone https://github.com/citusdata/postgresql-hll.git
- 创建一个名为
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/
- 创建一个
create_extension.sql
与 Dockerfile 同级的文件,内容如下:
CREATE EXTENSION hll;
- 建立你的形象:
# 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 的版本在尝试加载库时会出错。它在这里是为了完整性,也许有人可以为修复它做出贡献。
- 基于这个镜像运行一个容器
docker run -d --name hll hll:1.0
- 在新创建的容器中打开一个 shell:
docker exec -ti hll bash
- 在容器内运行:
su postgres
psql
\dx
输出应显示已安装的 hll 扩展。
推荐阅读
- javascript - 仅当另一个包含某些文本时,如何将数字添加到数组中
- javascript - 柏。如何 cy.url().should('eq', 'url_example/')?
- facebook - Facebook:使用公共 URL 共享唯一图像并在本地丢弃图像。是不是一直在FB?
- spring-batch - 为什么不将 Spring Data JPA 与批处理一起使用?
- php - Laravel - 如何使用对象数组制作多过滤器?
- c# - 如何使用 Media Foundation 修复曝光过度的高分辨率照片?
- java - 结合调度器和执行器服务的咖啡因
- javascript - Gem Chartkick 图表未在 PDF 上呈现
- wordpress - WordPress:为什么博客页面的永久链接是最新的博客文章
- python - 在使用 python SDK 创建 Azure VM 时添加 SSH 密钥