我正在尝试将postgis安装到postgres容器中。
Dockerfile:

FROM postgres:9.6.4-alpine

RUN apk update \
    && apk add -u postgresql-9.6-postgis-2.4 postgresql-9.6-postgis-2.4-scripts \
    && rm -rf /var/lib/apt/lists/*

COPY ./scripts/postgis.sh  /docker-entrypoint-initdb.d/postgis.sh

postgis.sh:
#!/bin/sh

for DB in $(psql -t -c  "SELECT datname from pg_database where datname = 'backend'"); do
    echo "Loading PostGIS extensions into $DB"
    "${psql[@]}" --dbname="$DB" <<-'EOSQL'
        CREATE EXTENSION IF NOT EXISTS postgis;
EOSQL
done

我收到此错误:



我发现类似的问题,例如:
  • ERROR: unsatisfiable constraints: while installing package in alpine
  • ERROR: unsatisfiable constraints - on php:7-fpm-alpine

  • 但这不能解决我的问题,如何使用apk将postgis扩展添加到我的postgres容器中?

    最佳答案

    Postgis软件包仅在边缘 Alpine 仓库中可用,而在稳定的仓库中不可用。这就是为什么您遇到“无法满足的约束”错误的原因。

    但是无论如何,您可以从边缘仓库中安装postgis:

    # 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 测试分支。

    关于docker - 错误: unsatisfiable constraints using apk in dockerfile,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48892448/

    10-15 13:03