1

From the postgis/postgis:13-3.1-alpine docker image I can push 3 shapefiles into my database using shp2pgsql in an init script.

But from the postgis/postgis:13-3.1 image I cannot:

(...)
db_1 | /docker-entrypoint-initdb.d/11_init.sh: 19: /docker-entrypoint-initdb.d/11_init.sh: shp2pgsql: not found
db_1 | /docker-entrypoint-initdb.d/11_init.sh: 20: /docker-entrypoint-initdb.d/11_init.sh: shp2pgsql: not found
db_1 | /docker-entrypoint-initdb.d/11_init.sh: 21: /docker-entrypoint-initdb.d/11_init.sh: shp2pgsql: not found

Both PostgreSQL and PostGIS version are however the same.

If it was designed for a specific purpose, why and which one?

Tip: to the present day (20210114), as an inelegant workaround is to install... the postgis apt package itself (yes, it sounds funky but it actually fixes the missing shp2pgsql binary)!

3
  • Fairly annoying once again. I think I had the same issue using the kartoza docker images, always had to install shp2pgsql again using apt.. Commented Jan 15, 2021 at 7:58
  • That being said, kartoza has this nice feature that you can launch and init script once the container has been built github.com/kartoza/docker-postgis#environment-variables maybe something similar exists in the official image? Commented Jan 15, 2021 at 8:08
  • 1
    The official postgis image does have a /docker-entrypoint.sh script and a /docker-entrypoint-initdb.d/ folder with a first init script 10_postgis.sh to actually install all the necessary postgis stuff. So you can plug whatever other script in that folder, following that they will be run in alphabetical order at startup. This is what I actually did to insert data using shp2pgsql e.g. You can play with it using: # docker run -it -e POSTGRES_PASSWORD=password postgis/postgis:13-3.1 and then connect to it. Commented Jan 15, 2021 at 17:40

1 Answer 1

2

I ran into the same problem and I think I might have a more elegant solution to this. You can use a multi stage docker build to install shp2pgsql and copy it to your final docker image. This would avoid to run apt get on your docker image.

# syntax=docker/dockerfile:1
FROM postgis/postgis:13-3.1 as builder
RUN apt update
RUN apt install -y postgis
RUN which shp2pgsql

FROM postgis/postgis:13-3.1

COPY --from=builder /usr/bin/shp2pgsql /usr/bin/shp2pgsql

# check shp2pgsql is installed
RUN shp2pgsql

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.