无法在 Alpine 图像上使用 PostGIS

Cant use PostGIS on Alpine image

我正在尝试使用 Alpine 图像来处理一些 Postgres 数据库 creation/preparation。 在容器里面,我是运行下面的命令:

createdb -e -O ${DB_USER} ${DB_NAME}
psql -e -d ${DB_NAME} -c "CREATE EXTENSION postgis;"

第一行工作正常,但第二行不行。

我已经用两个 docker 版本试过了:

  1. 以下 Dockerfile:
FROM alpine:3.6

RUN apk add -U postgresql

COPY ./db-creator.sh /db-creator.sh
CMD ["./db-creator.sh"]

这张图片给我以下错误:

CREATE EXTENSION postgis;
ERROR:  could not open extension control file "/usr/share/postgresql/10/extension/postgis.control": No such file or directory

我没有尝试直接安装 PostGIS,因为 this forum 中有人坚持认为 apk add -U postgresql 在裸 Alpine 图像上就足够了。

  1. 以下 Dockerfile:
FROM postgres:9.6.4-alpine

RUN apk add -U postgresql
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
RUN apk update && apk add -u postgis

COPY ./db-creator.sh /db-creator.sh
CMD ["./db-creator.sh"]

我添加了最后两个 运行 语句以遵循提到的内容 。在这种情况下,我无法直接安装 PostGIS 并得到以下错误:

fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/community/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/testing/x86_64/APKINDEX.tar.gz
WARNING: This apk-tools is OLD! Some packages might not function properly.
v3.6.5-44-gda55e27396 [http://dl-cdn.alpinelinux.org/alpine/v3.6/main]
v3.6.5-34-gf0ba0b43d5 [http://dl-cdn.alpinelinux.org/alpine/v3.6/community]
v20200117-229-g073aaff70d [http://dl-cdn.alpinelinux.org/alpine/edge/testing]
OK: 12520 distinct packages available
WARNING: This apk-tools is OLD! Some packages might not function properly.
  postgis (missing):
ERROR: unsatisfiable constraints:
    required by: world[postgis]

这到底是怎么回事 :)),我可以将 PostGISAlpine 图片一起使用吗?我是否需要使用其他图像版本或以不同方式安装 PostGIS

documentation 中所述,其他扩展部分:

When using the Alpine variants, any postgres extension not listed in postgres-contrib will need to be compiled in your own image (again, see github.com/appropriate/docker-postgis for a concrete example).

对于基于这里的 debian 是 docker 图像:

https://github.com/appropriate/docker-postgis/blob/f6d28e4a1871b1f72e1c893ff103f10b6d7cb6e1/10-2.4/Dockerfile

如果你想将 Postgis 与 PostgreSQL Alpine 图像捆绑在一起,你已经构建了它。