Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 421
user1685095 Avatar asked Dec 18 '14 13:12

user1685095


People also ask

Is PostGIS an extension?

PostGIS is an extension to PostgreSQL for storing and managing spatial information. To learn more about PostGIS, see PostGIS.net . Starting with version 10.5, PostgreSQL supports the libprotobuf 1.3. 0 library used by PostGIS for working with map box vector tile data.

Can I run postgres in docker?

Developers can perform Data Processing Operations using any Database Management System (DBMS) like PostgreSQL by pulling in their respective Docker Image files from the Docker Hub.


2 Answers

---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;
like image 138
macieks Avatar answered Sep 18 '22 18:09

macieks


I am using CentOS rather than Debian but ran into the same problem. The solution basically came down to using pg_ctl to start/stop postgres.

sudo -u postgres pg_ctl start -w -D ${PGDATA}

sudo -u postgres createdb postgis_template -E UTF8
sudo -u postgres psql -d postgis_template -c "create extension if not exists postgis;"

sudo -u postgres pg_ctl stop -w
like image 22
Solway01 Avatar answered Sep 18 '22 18:09

Solway01