├── .gitignore ├── Dockerfile ├── LICENSE ├── README.md ├── docker-compose.yml ├── init-postgis.sh ├── init-postgres.sh └── init-timescaledb.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # https://github.com/docker-library/postgres/blob/master/13/alpine/Dockerfile 2 | FROM postgres:13.4-alpine 3 | 4 | MAINTAINER Ivan Muratov, binakot@gmail.com 5 | 6 | # https://postgis.net/docs/manual-3.1/postgis_installation.html 7 | ENV POSTGIS_VERSION 3.1.4 8 | ENV POSTGIS_SHA256 dfcbad0c6090c80bc59d3ea77d1adc4b3ade533a403761b4af6d9a44be1a6e48 9 | RUN set -ex \ 10 | \ 11 | && apk add --no-cache --virtual .fetch-deps \ 12 | build-base \ 13 | ca-certificates \ 14 | openssl \ 15 | git \ 16 | tar \ 17 | && apk add --no-cache --virtual .build-deps \ 18 | --repository http://dl-cdn.alpinelinux.org/alpine/edge/main \ 19 | --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing \ 20 | make \ 21 | automake \ 22 | autoconf \ 23 | libtool \ 24 | file \ 25 | gcc \ 26 | g++ \ 27 | perl \ 28 | clang-dev \ 29 | llvm-dev \ 30 | libxml2-dev \ 31 | \ 32 | json-c-dev \ 33 | geos-dev \ 34 | gdal-dev \ 35 | proj-dev \ 36 | protobuf-c-dev \ 37 | postgresql-dev \ 38 | && apk add --no-cache --virtual .postgis-rundeps \ 39 | --repository http://dl-cdn.alpinelinux.org/alpine/edge/main \ 40 | --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing \ 41 | json-c \ 42 | geos \ 43 | gdal \ 44 | proj \ 45 | protobuf-c \ 46 | \ 47 | && wget -O postgis.tar.gz "https://github.com/postgis/postgis/archive/$POSTGIS_VERSION.tar.gz" \ 48 | && echo "$POSTGIS_SHA256 *postgis.tar.gz" | sha256sum -c - \ 49 | && mkdir -p /usr/src/postgis \ 50 | && tar \ 51 | --extract \ 52 | --file postgis.tar.gz \ 53 | --directory /usr/src/postgis \ 54 | --strip-components 1 \ 55 | && rm postgis.tar.gz \ 56 | \ 57 | && cd /usr/src/postgis \ 58 | && ./autogen.sh \ 59 | && ./configure \ 60 | && make -s \ 61 | && make -s install \ 62 | && cd / \ 63 | && rm -rf /usr/src/postgis \ 64 | && apk del .fetch-deps .build-deps 65 | 66 | # https://docs.timescale.com/timescaledb/latest/how-to-guides/install-timescaledb/self-hosted/ubuntu/installation-source 67 | ENV TIMESCALEDB_VERSION 2.4.2 68 | ENV TIMESCALEDB_SHA256 b206a376251259eb745eee819e7a853b3fbab9dc8443303714484a0fef89a2a4 69 | RUN set -ex \ 70 | && apk add --no-cache --virtual .fetch-deps \ 71 | build-base \ 72 | ca-certificates \ 73 | git \ 74 | tar \ 75 | && apk add --no-cache --virtual .build-deps \ 76 | --repository http://dl-cdn.alpinelinux.org/alpine/edge/main \ 77 | --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing \ 78 | make \ 79 | cmake \ 80 | gcc \ 81 | clang \ 82 | clang-dev \ 83 | llvm-dev \ 84 | dpkg \ 85 | dpkg-dev \ 86 | util-linux-dev \ 87 | libc-dev \ 88 | coreutils \ 89 | && apk add --no-cache --virtual .timescaledb-rundeps \ 90 | openssl \ 91 | openssl-dev \ 92 | \ 93 | && wget -O timescaledb.tar.gz "https://github.com/timescale/timescaledb/archive/$TIMESCALEDB_VERSION.tar.gz" \ 94 | && echo "$TIMESCALEDB_SHA256 *timescaledb.tar.gz" | sha256sum -c - \ 95 | && mkdir -p /usr/src/timescaledb \ 96 | && tar \ 97 | --extract \ 98 | --file timescaledb.tar.gz \ 99 | --directory /usr/src/timescaledb \ 100 | --strip-components 1 \ 101 | && rm timescaledb.tar.gz \ 102 | \ 103 | && cd /usr/src/timescaledb \ 104 | && ./bootstrap -DPROJECT_INSTALL_METHOD="docker" -DREGRESS_CHECKS=OFF \ 105 | && cd ./build && make install \ 106 | \ 107 | && cd / \ 108 | && rm -rf /usr/src/timescaledb \ 109 | && apk del .fetch-deps .build-deps \ 110 | && sed -r -i "s/[#]*\s*(shared_preload_libraries)\s*=\s*'(.*)'/\1 = 'timescaledb,\2'/;s/,'/'/" /usr/local/share/postgresql/postgresql.conf.sample 111 | 112 | COPY ./init-postgis.sh /docker-entrypoint-initdb.d/1.postgis.sh 113 | COPY ./init-timescaledb.sh /docker-entrypoint-initdb.d/2.timescaledb.sh 114 | COPY ./init-postgres.sh /docker-entrypoint-initdb.d/3.postgres.sh 115 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Ivan Muratov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PostgreSQL-PostGIS-TimescaleDB 2 | 3 | PostgreSQL + PostGIS + TimescaleDB ready-to-use docker image 🐘🌎📈 4 | 5 | Based on [Alpine Linux](https://alpinelinux.org). 6 | 7 | Docker image with: 8 | * [PostgreSQL](https://www.postgresql.org/) 9 | * [PostGIS](http://postgis.net/) 10 | * [TimescaleDB](https://www.timescale.com/) 11 | 12 | Current versions of components: 13 | * PostgreSQL: **13.4** ([Source docker image](https://store.docker.com/images/postgres)) 14 | * PostGIS: **3.1.4** ([Release archive](https://github.com/postgis/postgis/releases/tag/3.1.4)) 15 | * TimescaleDB: **2.4.2** ([Release archive](https://github.com/timescale/timescaledb/releases/tag/2.4.2)) 16 | 17 | How to build: 18 | 19 | ```bash 20 | $ docker build -t binakot/postgresql-postgis-timescaledb . 21 | ``` 22 | 23 | How to run: 24 | 25 | ```bash 26 | $ docker run -d --name postgres -e POSTGRES_PASSWORD=postgres binakot/postgresql-postgis-timescaledb 27 | ``` 28 | 29 | --- 30 | 31 | Also you can run app stack with built docker image and pgAdmin4: `docker-compose up`. 32 | 33 | PostgreSQL is running on port 5432. 34 | 35 | PgAdmin will be available on [localhost:5433](http://localhost:5433) with credentials: `admin@admin.com` / `admin`. 36 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | networks: 4 | overlay: 5 | 6 | volumes: 7 | pg_data: 8 | driver: local 9 | 10 | services: 11 | postgres: 12 | image: binakot/postgresql-postgis-timescaledb:latest 13 | container_name: postgres 14 | restart: unless-stopped 15 | environment: 16 | - POSTGRES_DB=postgres 17 | - POSTGRES_USER=postgres 18 | - POSTGRES_PASSWORD=postgres 19 | ports: 20 | - 5432:5432 21 | networks: 22 | - overlay 23 | volumes: 24 | - pg_data:/var/lib/postgresql/data 25 | 26 | pgadmin: 27 | image: dpage/pgadmin4:latest 28 | container_name: pgadmin 29 | restart: unless-stopped 30 | environment: 31 | - PGADMIN_DEFAULT_EMAIL=admin@admin.com 32 | - PGADMIN_DEFAULT_PASSWORD=admin 33 | ports: 34 | - 5433:80 35 | networks: 36 | - overlay 37 | -------------------------------------------------------------------------------- /init-postgis.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | # Create the 'template_postgis' template db 6 | psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL 7 | CREATE DATABASE template_postgis; 8 | UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template_postgis'; 9 | EOSQL 10 | 11 | # Load PostGIS into both template_database and $POSTGRES_DB 12 | for DB in template_postgis "$POSTGRES_DB"; do 13 | echo "Loading PostGIS extensions into $DB" 14 | psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname="$DB" <<-EOSQL 15 | CREATE EXTENSION IF NOT EXISTS postgis CASCADE; 16 | CREATE EXTENSION IF NOT EXISTS postgis_topology CASCADE; 17 | EOSQL 18 | done 19 | -------------------------------------------------------------------------------- /init-postgres.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL 6 | SELECT version(); 7 | SELECT extname, extversion from pg_extension; 8 | EOSQL 9 | -------------------------------------------------------------------------------- /init-timescaledb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | # Create the 'template_timescaledb' template db 6 | psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL 7 | CREATE DATABASE template_timescaledb; 8 | UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template_timescaledb'; 9 | EOSQL 10 | 11 | # Load TimescaleDB into both template_database and $POSTGRES_DB 12 | for DB in template_timescaledb "$POSTGRES_DB"; do 13 | echo "Loading TimescaleDB extensions into $DB" 14 | psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname="$DB" <<-EOSQL 15 | CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE; 16 | EOSQL 17 | done 18 | --------------------------------------------------------------------------------