Postgis软件包仅在 edge alpine repo 中可用,而不是在稳定版中。这就是为什么您会收到“不可满足的约束”错误。
但无论如何,您可以postgis
从 edge repo 安装:
# echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
# apk update
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/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.5.2-254-g9d4623dc57 [http://dl-cdn.alpinelinux.org/alpine/v3.5/main]
v3.5.2-247-gc85efb30e1 [http://dl-cdn.alpinelinux.org/alpine/v3.5/community]
v3.7.0-2163-ge03552fc58 [http://dl-cdn.alpinelinux.org/alpine/edge/testing]
OK: 10930 distinct packages available
# apk search --no-cache postgis
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/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.
postgis-dev-2.4.1-r1
postgis-2.4.1-r1
postgis-doc-2.4.1-r1
所以,最终结果Dockerfile
是:
FROM postgres:9.6.4-alpine
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
RUN apk update \
&& apk add -u postgis \
&& rm -rf /var/lib/apt/lists/*
COPY ./scripts/postgis.sh /docker-entrypoint-initdb.d/postgis.sh
2020 年 1 月 23 日更新:
从 Alpine 版本 3.11 开始, Postgis可在主要和社区存储库中使用:
/ # cat /etc/os-release
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.11.3
PRETTY_NAME="Alpine Linux v3.11"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://bugs.alpinelinux.org/"
/ #
/ # apk search --no-cache postgis
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz
postgis-3.0.0-r1
postgis-doc-3.0.0-r1
对于 Alpine 版本 3.11 及更高版本,您不需要使用边缘 repo 测试分支。