postgis / docker-postgis

Docker image for PostGIS
https://hub.docker.com/r/postgis/postgis/
MIT License
1.4k stars 468 forks source link

Install postgis into another schema, note the public one #372

Open mcherb opened 11 months ago

mcherb commented 11 months ago

Hi,

In my production environment, postgis is installed into a schema called postgis. Now I'm using postgis/postgis:10-3.0 but by default this image install postgis into the public schema.

Is there a way to make this schema controlled by a environment variable ?

ImreSamu commented 11 months ago

Is there a way to make this schema controlled by a environment variable ?

I'm not entirely sure I understand your issue, but if you want to customize the PostGIS initialization script (/docker-entrypoint-initdb.d/10_postgis.sh), you can use your own custom script by mapping it in a Docker file like this:

Additionally, you might need to modify it to correctly use the 'CREATE EXTENSION' command as described here:

And this is the the contents of postgis/postgis:10-3.0 - /docker-entrypoint-initdb.d/10_postgis.sh:

$ docker run -it --rm  postgis/postgis:10-3.0 cat /docker-entrypoint-initdb.d/10_postgis.sh

#!/bin/sh

set -e

# Perform all actions as $POSTGRES_USER
export PGUSER="$POSTGRES_USER"

# Create the 'template_postgis' template db
"${psql[@]}" <<- 'EOSQL'
CREATE DATABASE template_postgis IS_TEMPLATE true;
EOSQL

# Load PostGIS into both template_database and $POSTGRES_DB
for DB in template_postgis "$POSTGRES_DB"; do
    echo "Loading PostGIS extensions into $DB"
    "${psql[@]}" --dbname="$DB" <<-'EOSQL'
        CREATE EXTENSION IF NOT EXISTS postgis;
        CREATE EXTENSION IF NOT EXISTS postgis_topology;
        CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;
        CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder;
EOSQL
done
ImreSamu commented 11 months ago

related:

https://gis.stackexchange.com/questions/87212/add-postgis-spatial-functions-to-a-custom-schema-other-than-public-in-postgres

mcherb commented 11 months ago

Thanks for your replay :)

stmtk1 commented 10 months ago

In this image, the environment variables POSTGRES_DB, POSTGRES_USER and POSTGRES_PASSWORD can be used to change the database name, user name and password name, but not the schema name. So we want to be able to change the schema name using the new environment variable POSTGRES_SCHEMA.