Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cant use PostGIS on Alpine image

Tags:

I'm trying to use the Alpine image to take care of some Postgres db creation/preparation. Inside the container, I am running the following commands:

createdb -e -O ${DB_USER} ${DB_NAME}
psql -e -d ${DB_NAME} -c "CREATE EXTENSION postgis;"

The first line works fine, but the second does NOT.

I have tried this with two docker builds:

  1. The following Dockerfile:
FROM alpine:3.6

RUN apk add -U postgresql

COPY ./db-creator.sh /db-creator.sh
CMD ["./db-creator.sh"]

This image gives me the following error:

CREATE EXTENSION postgis;
ERROR:  could not open extension control file "/usr/share/postgresql/10/extension/postgis.control": No such file or directory

I didn't try to install PostGIS directly as someone in this forum insisted that apk add -U postgresql on a bare Alpine image should suffice.

  1. The following Dockerfile:
FROM postgres:9.6.4-alpine

RUN apk add -U postgresql
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
RUN apk update && apk add -u postgis

COPY ./db-creator.sh /db-creator.sh
CMD ["./db-creator.sh"]

I added the last two RUN statements to follow what was mentioned here. In this case, I am unable to directly install PostGIS and get the following error:

fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/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.6.5-44-gda55e27396 [http://dl-cdn.alpinelinux.org/alpine/v3.6/main]
v3.6.5-34-gf0ba0b43d5 [http://dl-cdn.alpinelinux.org/alpine/v3.6/community]
v20200117-229-g073aaff70d [http://dl-cdn.alpinelinux.org/alpine/edge/testing]
OK: 12520 distinct packages available
WARNING: This apk-tools is OLD! Some packages might not function properly.
  postgis (missing):
ERROR: unsatisfiable constraints:
    required by: world[postgis]

How on earth :)), can I use PostGIS with the Alpine image? Do I need to use other image versions or install PostGIS differently?

like image 410
mhyousefi Avatar asked Jan 22 '20 14:01

mhyousefi


1 Answers

As mentioned in the documentation, Additional Extensions section:

When using the Alpine variants, any postgres extension not listed in postgres-contrib will need to be compiled in your own image (again, see github.com/appropriate/docker-postgis for a concrete example).

For debian based here is the docker image:

https://github.com/appropriate/docker-postgis/blob/f6d28e4a1871b1f72e1c893ff103f10b6d7cb6e1/10-2.4/Dockerfile

If you want to bundle Postgis with PostgreSQL Alpine image you have build it.

like image 76
ROOT Avatar answered Oct 11 '22 02:10

ROOT