From c8e7fb2394fa8589f50751cb2a2e026e9f033c12 Mon Sep 17 00:00:00 2001 From: antoineludeau <52679050+antoineludeau@users.noreply.github.com> Date: Thu, 28 Sep 2023 07:29:35 +0200 Subject: [PATCH] Added a custom dockerfile for postgres to install and activate postgis --- docker-compose.yml | 3 ++- docker-resources/postgres/Dockerfile.dev | 8 ++++++++ docker-resources/postgres/init-postgis.sh | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 docker-resources/postgres/Dockerfile.dev create mode 100644 docker-resources/postgres/init-postgis.sh diff --git a/docker-compose.yml b/docker-compose.yml index 30e1af6b..6bf6c685 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,7 +7,8 @@ services: volumes: - db-mongo:/data/db db-postgres: - image: postgres:15-alpine + build: + dockerfile: docker-resources/postgres/Dockerfile.dev ports: - "${POSTGRES_PORT:-5432}:5432" environment: diff --git a/docker-resources/postgres/Dockerfile.dev b/docker-resources/postgres/Dockerfile.dev new file mode 100644 index 00000000..1f695065 --- /dev/null +++ b/docker-resources/postgres/Dockerfile.dev @@ -0,0 +1,8 @@ +# Use the official PostgreSQL image as the base image +FROM postgres:15 + +# Install PostGIS extension +RUN apt-get update && apt-get install -y postgresql-15-postgis-3 + +# Copy a script to activate PostGIS +COPY docker-resources/postgres/init-postgis.sh /docker-entrypoint-initdb.d \ No newline at end of file diff --git a/docker-resources/postgres/init-postgis.sh b/docker-resources/postgres/init-postgis.sh new file mode 100644 index 00000000..2a0b5488 --- /dev/null +++ b/docker-resources/postgres/init-postgis.sh @@ -0,0 +1,5 @@ +#!/bin/bash +set -e + +echo "Activating PostGIS extension..." +psql -U $POSTGRES_USER -d $POSTGRES_DB -c "CREATE EXTENSION postgis;" \ No newline at end of file