ERROR: unsatisfiable constraints using apk in dockerfile
Asked Answered
N

3

31

I'm trying to install postgis into a postgres container. 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

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

I found similar questions such as :

  1. ERROR: unsatisfiable constraints: while installing package in alpine
  2. ERROR: unsatisfiable constraints - on php:7-fpm-alpine

But it doesn't solve my problem.How can I add postgis extension to my postgres container with apk?

Neonatal answered 20/2, 2018 at 19:2 Comment(0)
Q
28

Postgis package is only available in edge alpine repo, not in a stable one. That's why you are getting "unsatisfiable constraints" error.

But anyway you can install postgis from 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

So, the final Dockerfile is:

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:

Postgis is available in main and community repositories starting from Alpine version 3.11:

/ # 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.

Quiteris answered 20/2, 2018 at 19:51 Comment(3)
I get the following error when following your instructions: postgis (missing): ERROR: unsatisfiable constraints: required by: world[postgis]. I used the following command: echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories && apk update && apk add -u postgis && rm -rf /var/lib/apt/lists/*Pygmy
I also tried to install PostGIS directly on an Alpine image, but stumbled upon a similar issue. I posted a question about it. I appreciate if you could help.Pygmy
@Pygmy I've updated my answer. Some changes have been done in Alpine world since I answered the question.Quiteris
B
6

Old:

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

New:

apk add --no-cache curl jq python3 py3-pip
Biflagellate answered 3/6, 2020 at 17:15 Comment(0)
M
-1

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

Madge answered 4/1, 2021 at 15:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.