Search code examples
postgresqldockerpostgis

How to create postgis extension for postgresql in docker?


I'm getting errors when trying to create postgis extensions.

Here is what my dockerfile looks like.

    from postgres
RUN apt-get update && apt-get install postgis -y
ADD /create_postgis_extension.sh /docker-entrypoint-initdb.d/

create.bla-bla..sh

#!/bin/sh
POSTGRES="gosu postgres postgres"

$POSTGRES --single -E <<EOSQL
CREATE EXTENSION postgis;
CREATE EXTENSION postgis_topology;
EOSQL

And here is the error when running the image

backend> statement: CREATE EXTENSION postgis;

ERROR: type addbandarg[] does not exist STATEMENT: CREATE EXTENSION postgis;

backend> statement: CREATE EXTENSION postgis_topology;

backend> ERROR: required extension "postgis" is not installed

I'm doing something wrong obviously, but I don't know what. Why is postgis in not installed if I've installed postgis with apt-get.


Solution

  • ---DOCKERFILE

    FROM postgres:12.4
    
    RUN apt-get update \
        && apt-get install wget -y \
        && apt-get install postgresql-12-postgis-3 -y \
        && apt-get install postgis -y
    
    COPY ./db.sql /docker-entrypoint-initdb.d/
    

    --- db.sql (in this same folder)

    CREATE EXTENSION postgis;