简体   繁体   English

错误:在 dockerfile 中使用 apk 无法满足约束

[英]ERROR: unsatisfiable constraints using apk in dockerfile

I'm trying to install postgis into a postgres container.我正在尝试将 postgis 安装到 postgres 容器中。 Dockerfile: 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: 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

I got this error:我收到此错误:

ERROR: unsatisfiable constraints: postgresql-9.6-postgis-2.4 (missing): required by: world[postgresql-9.6-postgis-2.4] postgresql-9.6-postgis-2.4-scripts (missing): required by: world[postgresql-9.6-postgis-2.4-scripts] The command '/bin/sh -c apk update && apk add -u postgresql-9.6-postgis-2.4 postgresql-9.6-postgis-2.4-scripts && rm -rf /var/lib/apt/lists/*' returned a non-zero code: 2错误:无法满足的约束:postgresql-9.6-postgis-2.4(缺失):需要:world[postgresql-9.6-postgis-2.4] postgresql-9.6-postgis-2.4-scripts(缺失):需要:world[postgresql-9.6 -postgis-2.4-scripts] 命令'/bin/sh -c apk update && apk add -u postgresql-9.6-postgis-2.4 postgresql-9.6-postgis-2.4-scripts && rm -rf /var/lib/apt/ list/*' 返回了一个非零代码:2

I found similar questions such as :我发现了类似的问题,例如:

  1. ERROR: unsatisfiable constraints: while installing package in alpine 错误:无法满足的约束:在 alpine 中安装软件包时
  2. ERROR: unsatisfiable constraints - on php:7-fpm-alpine 错误:无法满足的约束 - 在 php:7-fpm-alpine 上

But it doesn't solve my problem.How can I add postgis extension to my postgres container with apk?但这并没有解决我的问题。如何使用 apk 将 postgis 扩展添加到我的 postgres 容器中?

Postgis package is only available in edge alpine repo, not in a stable one. Postgis包仅在 edge alpine repo 中可用,在稳定版中不可用。 That's why you are getting "unsatisfiable constraints" error.这就是为什么您会收到“无法满足的约束”错误的原因。

But anyway you can install postgis from edge repo:但无论如何,您可以从 edge repo 安装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

So, the final Dockerfile is:所以,最终的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

UPDATED on January 23th 2020: 2020 年 1 月 23 日更新:

Postgis is available in main and community repositories starting from Alpine version 3.11:从 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

You don't need to use edge repo testing branch for Alpine version 3.11 and later.对于 Alpine 3.11 及更高版本,您不需要使用 edge repo testing 分支。

Old:旧:

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

New:新:

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

It is weird but in my case solution was as simple as to run:这很奇怪,但在我的情况下,解决方案就像运行一样简单:

sudo systemctl restart docker

... on a machine where you running docker containers ...在运行 docker 容器的机器上

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM