Search code examples
postgresqldockerpostgis

Install Postgis in docker container


I created a database with Docker using the postgres image as usual

docker run -d \       
    --name some-postgres \
    -e POSTGRES_PASSWORD=mypassword \
    -v ${HOME}/postgres-data/:/var/lib/postgresql/data \
    -p 5432:5432 \
    postgres

now I decided to add a new column in one of the tables to store coordinates using PostGIS, however when I do

CREATE EXTENSION postgis;

or something similar I get this error message:

ERROR:  could not open extension control file "/usr/share/postgresql/12/extension/postgis.control": No such file or directory

Is there an additional step one has to take before running the Docker container in order to install PostGIS?


Solution

  • The postgis extension does not come with vanilla postgres, which does ship with a whole bunch of more general purpose extensions, though nothing notable for geospatial. Take a look at this instead: https://registry.hub.docker.com/r/postgis/postgis/