错误:在dockerfile

时间:2018-02-20 19:02:44

标签: docker apk alpine

我试图将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

我收到了这个错误:

  

错误:不满意的约束:     postgresql-9.6-postgis-2.4(缺失):       要求:                    世界[PostgreSQL的-9.6的PostGIS-2.4]     postgresql-9.6-postgis-2.4-scripts(缺失):       要求:                    世界[PostgreSQL的-9.6的PostGIS-2.4-脚本]   命令&#39; / bin / sh -c apk更新&amp;&amp; apk add -u postgresql-9.6-postgis-2.4 postgresql-9.6-postgis-2.4-scripts&amp;&amp; rm -rf / var / lib / apt / lists / *&#39;返回非零代码:2

我发现了类似的问题,例如:

  1. ERROR: unsatisfiable constraints: while installing package in alpine
  2. ERROR: unsatisfiable constraints - on php:7-fpm-alpine
  3. 但它并没有解决我的问题。如何用apk添加postgis扩展到我的postgres容器?

3 个答案:

答案 0 :(得分:9)

Postgis包只适用于边缘高山回购,而不是稳定的回购。这就是为什么你得到了不可满足的约束&#34;错误。

但是无论如何你可以从边缘仓库安装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

答案 1 :(得分:3)

旧:

apk add --no-cache curl jq python py-pip

新功能:

apk add --no-cache curl jq python3 py3-pip

答案 2 :(得分:0)

这很奇怪,但就我而言,解决方案就像运行一样简单:

delete

... 在运行 docker 容器的机器上