diff --git a/.travis.yml b/.travis.yml index 9134c815..bbbd83ff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ services: docker dist: trusty env: + - VERSION=9.6-2.4 - VERSION=9.6-2.3 - VERSION=9.6-2.3 VARIANT=alpine - VERSION=9.5-2.3 @@ -15,6 +16,7 @@ env: - VERSION=9.3-2.3 VARIANT=alpine - VERSION=9.2-2.3 - VERSION=9.2-2.3 VARIANT=alpine + - VERSION=10-2.4 install: - git clone https://github.com/docker-library/official-images.git ~/official-images diff --git a/10-2.4/Dockerfile b/10-2.4/Dockerfile new file mode 100644 index 00000000..4476446f --- /dev/null +++ b/10-2.4/Dockerfile @@ -0,0 +1,17 @@ +FROM postgres:10 +MAINTAINER Mike Dillon + +ENV POSTGIS_MAJOR 2.4 +ENV POSTGIS_VERSION 2.4.0+dfsg-1.pgdg90+1 + +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR=$POSTGIS_VERSION \ + postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR-scripts=$POSTGIS_VERSION \ + postgis\ + && rm -rf /var/lib/apt/lists/* + +RUN mkdir -p /docker-entrypoint-initdb.d +COPY ./initdb-postgis.sh /docker-entrypoint-initdb.d/postgis.sh +COPY ./update-postgis.sh /usr/local/bin + diff --git a/10-2.4/README.md b/10-2.4/README.md new file mode 100644 index 00000000..feb4ea09 --- /dev/null +++ b/10-2.4/README.md @@ -0,0 +1,51 @@ +# mdillon/postgis + +[![Build Status](https://travis-ci.org/appropriate/docker-postgis.svg)](https://travis-ci.org/appropriate/docker-postgis) [![Join the chat at https://gitter.im/appropriate/docker-postgis](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/appropriate/docker-postgis?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) + +The `mdillon/postgis` image provides a Docker container running Postgres 9 with [PostGIS 2.3](http://postgis.net/) installed, or Postgres 10 with [PostGIS 2.4](http://postgis.net/) installed. This image is based on the official [`postgres`](https://registry.hub.docker.com/_/postgres/) image and provides variants for each version of Postgres 9 supported by the base image (9.2-9.6) and Postgres 10. + +This image ensures that the default database created by the parent `postgres` image will have the following extensions installed: + +* `postgis` +* `postgis_topology` +* `fuzzystrmatch` +* `postgis_tiger_geocoder` + +Unless `-e POSTGRES_DB` is passed to the container at startup time, this database will be named after the admin user (either `postgres` or the user specified with `-e POSTGRES_USER`). If you would prefer to use the older template database mechanism for enabling PostGIS, the image also provides a PostGIS-enabled template database called `template_postgis`. + +## Usage + +In order to run a basic container capable of serving a PostGIS-enabled database, start a container as follows: + + docker run --name some-postgis -e POSTGRES_PASSWORD=mysecretpassword -d mdillon/postgis + +For more detailed instructions about how to start and control your Postgres container, see the documentation for the `postgres` image [here](https://registry.hub.docker.com/_/postgres/). + +Once you have started a database container, you can then connect to the database as follows: + + docker run -it --link some-postgis:postgres --rm postgres \ + sh -c 'exec psql -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U postgres' + +See [the PostGIS documentation](http://postgis.net/docs/postgis_installation.html#create_new_db_extensions) for more details on your options for creating and using a spatially-enabled database. + +## Known Issues / Errors + +When You encouter errors due to PostGIS update `OperationalError: could not access file "$libdir/postgis-X.X`, run: + +`docker exec some-postgis update-postgis.sh` + +It will update to Your newest PostGIS. Update is idempotent, so it won't hurt when You run it more than once, You will get notification like: + +``` +Updating PostGIS extensions template_postgis to X.X.X +NOTICE: version "X.X.X" of extension "postgis" is already installed +NOTICE: version "X.X.X" of extension "postgis_topology" is already installed +NOTICE: version "X.X.X" of extension "postgis_tiger_geocoder" is already installed +ALTER EXTENSION +Updating PostGIS extensions docker to X.X.X +NOTICE: version "X.X.X" of extension "postgis" is already installed +NOTICE: version "X.X.X" of extension "postgis_topology" is already installed +NOTICE: version "X.X.X" of extension "postgis_tiger_geocoder" is already installed +ALTER EXTENSION +``` + diff --git a/10-2.4/initdb-postgis.sh b/10-2.4/initdb-postgis.sh new file mode 100755 index 00000000..43012885 --- /dev/null +++ b/10-2.4/initdb-postgis.sh @@ -0,0 +1,23 @@ +#!/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; +UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template_postgis'; +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 diff --git a/10-2.4/update-postgis.sh b/10-2.4/update-postgis.sh new file mode 100755 index 00000000..5d1088f2 --- /dev/null +++ b/10-2.4/update-postgis.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +set -e + +# Perform all actions as $POSTGRES_USER +export PGUSER="$POSTGRES_USER" + +POSTGIS_VERSION="${POSTGIS_VERSION%%+*}" + +# Load PostGIS into both template_database and $POSTGRES_DB +for DB in template_postgis "$POSTGRES_DB"; do + echo "Updating PostGIS extensions $DB to $POSTGIS_VERSION" + psql --dbname="$DB" -c " + -- Upgrade PostGIS (includes raster) + ALTER EXTENSION postgis UPDATE TO '$POSTGIS_VERSION'; + -- Upgrade Topology + ALTER EXTENSION postgis_topology UPDATE TO '$POSTGIS_VERSION'; + -- Upgrade US Tiger Geocoder + ALTER EXTENSION postgis_tiger_geocoder UPDATE TO '$POSTGIS_VERSION'; + " +done diff --git a/9.2-2.3/Dockerfile b/9.2-2.3/Dockerfile index b5466818..22970bca 100644 --- a/9.2-2.3/Dockerfile +++ b/9.2-2.3/Dockerfile @@ -2,13 +2,13 @@ FROM postgres:9.2 MAINTAINER Mike Dillon ENV POSTGIS_MAJOR 2.3 -ENV POSTGIS_VERSION 2.3.2+dfsg-1~exp2.pgdg80+1 +ENV POSTGIS_VERSION 2.3.3+dfsg-1.pgdg80+1 RUN apt-get update \ && apt-get install -y --no-install-recommends \ postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR=$POSTGIS_VERSION \ postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR-scripts=$POSTGIS_VERSION \ - postgis=$POSTGIS_VERSION \ + postgis\ && rm -rf /var/lib/apt/lists/* RUN mkdir -p /docker-entrypoint-initdb.d diff --git a/9.2-2.3/README.md b/9.2-2.3/README.md index efdee8cc..feb4ea09 100644 --- a/9.2-2.3/README.md +++ b/9.2-2.3/README.md @@ -2,7 +2,7 @@ [![Build Status](https://travis-ci.org/appropriate/docker-postgis.svg)](https://travis-ci.org/appropriate/docker-postgis) [![Join the chat at https://gitter.im/appropriate/docker-postgis](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/appropriate/docker-postgis?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -The `mdillon/postgis` image provides a Docker container running Postgres 9 with [PostGIS 2.3](http://postgis.net/) installed. This image is based on the official [`postgres`](https://registry.hub.docker.com/_/postgres/) image and provides variants for each version of Postgres 9 supported by the base image (9.2-9.6). +The `mdillon/postgis` image provides a Docker container running Postgres 9 with [PostGIS 2.3](http://postgis.net/) installed, or Postgres 10 with [PostGIS 2.4](http://postgis.net/) installed. This image is based on the official [`postgres`](https://registry.hub.docker.com/_/postgres/) image and provides variants for each version of Postgres 9 supported by the base image (9.2-9.6) and Postgres 10. This image ensures that the default database created by the parent `postgres` image will have the following extensions installed: diff --git a/9.2-2.3/alpine/Dockerfile b/9.2-2.3/alpine/Dockerfile index de3a23ea..ab36d9a5 100644 --- a/9.2-2.3/alpine/Dockerfile +++ b/9.2-2.3/alpine/Dockerfile @@ -1,8 +1,8 @@ FROM postgres:9.2-alpine MAINTAINER Régis Belson -ENV POSTGIS_VERSION 2.3.2 -ENV POSTGIS_SHA256 7e82c6994acc80c9f6ea57c0c4a1e0f9372c9fa314c9da148486f395bd1dced9 +ENV POSTGIS_VERSION 2.3.3 +ENV POSTGIS_SHA256 3403d5635b4b86c90f6a225a366a515c6bc734d1bad625c7df4e8c6fde7e8588 RUN set -ex \ \ diff --git a/9.3-2.3/Dockerfile b/9.3-2.3/Dockerfile index 559b2f81..46500269 100644 --- a/9.3-2.3/Dockerfile +++ b/9.3-2.3/Dockerfile @@ -2,13 +2,13 @@ FROM postgres:9.3 MAINTAINER Mike Dillon ENV POSTGIS_MAJOR 2.3 -ENV POSTGIS_VERSION 2.3.2+dfsg-1~exp2.pgdg80+1 +ENV POSTGIS_VERSION 2.3.3+dfsg-1.pgdg80+1 RUN apt-get update \ && apt-get install -y --no-install-recommends \ postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR=$POSTGIS_VERSION \ postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR-scripts=$POSTGIS_VERSION \ - postgis=$POSTGIS_VERSION \ + postgis\ && rm -rf /var/lib/apt/lists/* RUN mkdir -p /docker-entrypoint-initdb.d diff --git a/9.3-2.3/README.md b/9.3-2.3/README.md index efdee8cc..feb4ea09 100644 --- a/9.3-2.3/README.md +++ b/9.3-2.3/README.md @@ -2,7 +2,7 @@ [![Build Status](https://travis-ci.org/appropriate/docker-postgis.svg)](https://travis-ci.org/appropriate/docker-postgis) [![Join the chat at https://gitter.im/appropriate/docker-postgis](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/appropriate/docker-postgis?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -The `mdillon/postgis` image provides a Docker container running Postgres 9 with [PostGIS 2.3](http://postgis.net/) installed. This image is based on the official [`postgres`](https://registry.hub.docker.com/_/postgres/) image and provides variants for each version of Postgres 9 supported by the base image (9.2-9.6). +The `mdillon/postgis` image provides a Docker container running Postgres 9 with [PostGIS 2.3](http://postgis.net/) installed, or Postgres 10 with [PostGIS 2.4](http://postgis.net/) installed. This image is based on the official [`postgres`](https://registry.hub.docker.com/_/postgres/) image and provides variants for each version of Postgres 9 supported by the base image (9.2-9.6) and Postgres 10. This image ensures that the default database created by the parent `postgres` image will have the following extensions installed: diff --git a/9.3-2.3/alpine/Dockerfile b/9.3-2.3/alpine/Dockerfile index f667c7cd..f7a0d5fe 100644 --- a/9.3-2.3/alpine/Dockerfile +++ b/9.3-2.3/alpine/Dockerfile @@ -1,8 +1,8 @@ FROM postgres:9.3-alpine MAINTAINER Régis Belson -ENV POSTGIS_VERSION 2.3.2 -ENV POSTGIS_SHA256 7e82c6994acc80c9f6ea57c0c4a1e0f9372c9fa314c9da148486f395bd1dced9 +ENV POSTGIS_VERSION 2.3.3 +ENV POSTGIS_SHA256 3403d5635b4b86c90f6a225a366a515c6bc734d1bad625c7df4e8c6fde7e8588 RUN set -ex \ \ diff --git a/9.4-2.3/Dockerfile b/9.4-2.3/Dockerfile index 7c968703..f4f8dead 100644 --- a/9.4-2.3/Dockerfile +++ b/9.4-2.3/Dockerfile @@ -2,13 +2,13 @@ FROM postgres:9.4 MAINTAINER Mike Dillon ENV POSTGIS_MAJOR 2.3 -ENV POSTGIS_VERSION 2.3.2+dfsg-1~exp2.pgdg80+1 +ENV POSTGIS_VERSION 2.3.3+dfsg-1.pgdg80+1 RUN apt-get update \ && apt-get install -y --no-install-recommends \ postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR=$POSTGIS_VERSION \ postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR-scripts=$POSTGIS_VERSION \ - postgis=$POSTGIS_VERSION \ + postgis\ && rm -rf /var/lib/apt/lists/* RUN mkdir -p /docker-entrypoint-initdb.d diff --git a/9.4-2.3/README.md b/9.4-2.3/README.md index efdee8cc..feb4ea09 100644 --- a/9.4-2.3/README.md +++ b/9.4-2.3/README.md @@ -2,7 +2,7 @@ [![Build Status](https://travis-ci.org/appropriate/docker-postgis.svg)](https://travis-ci.org/appropriate/docker-postgis) [![Join the chat at https://gitter.im/appropriate/docker-postgis](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/appropriate/docker-postgis?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -The `mdillon/postgis` image provides a Docker container running Postgres 9 with [PostGIS 2.3](http://postgis.net/) installed. This image is based on the official [`postgres`](https://registry.hub.docker.com/_/postgres/) image and provides variants for each version of Postgres 9 supported by the base image (9.2-9.6). +The `mdillon/postgis` image provides a Docker container running Postgres 9 with [PostGIS 2.3](http://postgis.net/) installed, or Postgres 10 with [PostGIS 2.4](http://postgis.net/) installed. This image is based on the official [`postgres`](https://registry.hub.docker.com/_/postgres/) image and provides variants for each version of Postgres 9 supported by the base image (9.2-9.6) and Postgres 10. This image ensures that the default database created by the parent `postgres` image will have the following extensions installed: diff --git a/9.4-2.3/alpine/Dockerfile b/9.4-2.3/alpine/Dockerfile index c0735ccb..1c664f21 100644 --- a/9.4-2.3/alpine/Dockerfile +++ b/9.4-2.3/alpine/Dockerfile @@ -1,8 +1,8 @@ FROM postgres:9.4-alpine MAINTAINER Régis Belson -ENV POSTGIS_VERSION 2.3.2 -ENV POSTGIS_SHA256 7e82c6994acc80c9f6ea57c0c4a1e0f9372c9fa314c9da148486f395bd1dced9 +ENV POSTGIS_VERSION 2.3.3 +ENV POSTGIS_SHA256 3403d5635b4b86c90f6a225a366a515c6bc734d1bad625c7df4e8c6fde7e8588 RUN set -ex \ \ diff --git a/9.5-2.3/Dockerfile b/9.5-2.3/Dockerfile index 0c2e8372..b9b833c2 100644 --- a/9.5-2.3/Dockerfile +++ b/9.5-2.3/Dockerfile @@ -2,13 +2,13 @@ FROM postgres:9.5 MAINTAINER Mike Dillon ENV POSTGIS_MAJOR 2.3 -ENV POSTGIS_VERSION 2.3.2+dfsg-1~exp2.pgdg80+1 +ENV POSTGIS_VERSION 2.3.3+dfsg-1.pgdg80+1 RUN apt-get update \ && apt-get install -y --no-install-recommends \ postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR=$POSTGIS_VERSION \ postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR-scripts=$POSTGIS_VERSION \ - postgis=$POSTGIS_VERSION \ + postgis\ && rm -rf /var/lib/apt/lists/* RUN mkdir -p /docker-entrypoint-initdb.d diff --git a/9.5-2.3/README.md b/9.5-2.3/README.md index efdee8cc..feb4ea09 100644 --- a/9.5-2.3/README.md +++ b/9.5-2.3/README.md @@ -2,7 +2,7 @@ [![Build Status](https://travis-ci.org/appropriate/docker-postgis.svg)](https://travis-ci.org/appropriate/docker-postgis) [![Join the chat at https://gitter.im/appropriate/docker-postgis](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/appropriate/docker-postgis?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -The `mdillon/postgis` image provides a Docker container running Postgres 9 with [PostGIS 2.3](http://postgis.net/) installed. This image is based on the official [`postgres`](https://registry.hub.docker.com/_/postgres/) image and provides variants for each version of Postgres 9 supported by the base image (9.2-9.6). +The `mdillon/postgis` image provides a Docker container running Postgres 9 with [PostGIS 2.3](http://postgis.net/) installed, or Postgres 10 with [PostGIS 2.4](http://postgis.net/) installed. This image is based on the official [`postgres`](https://registry.hub.docker.com/_/postgres/) image and provides variants for each version of Postgres 9 supported by the base image (9.2-9.6) and Postgres 10. This image ensures that the default database created by the parent `postgres` image will have the following extensions installed: diff --git a/9.5-2.3/alpine/Dockerfile b/9.5-2.3/alpine/Dockerfile index 8bd79774..332c646f 100644 --- a/9.5-2.3/alpine/Dockerfile +++ b/9.5-2.3/alpine/Dockerfile @@ -1,8 +1,8 @@ FROM postgres:9.5-alpine MAINTAINER Régis Belson -ENV POSTGIS_VERSION 2.3.2 -ENV POSTGIS_SHA256 7e82c6994acc80c9f6ea57c0c4a1e0f9372c9fa314c9da148486f395bd1dced9 +ENV POSTGIS_VERSION 2.3.3 +ENV POSTGIS_SHA256 3403d5635b4b86c90f6a225a366a515c6bc734d1bad625c7df4e8c6fde7e8588 RUN set -ex \ \ diff --git a/9.6-2.3/Dockerfile b/9.6-2.3/Dockerfile index 31c00664..961f0a49 100644 --- a/9.6-2.3/Dockerfile +++ b/9.6-2.3/Dockerfile @@ -2,13 +2,13 @@ FROM postgres:9.6 MAINTAINER Mike Dillon ENV POSTGIS_MAJOR 2.3 -ENV POSTGIS_VERSION 2.3.2+dfsg-1~exp2.pgdg80+1 +ENV POSTGIS_VERSION 2.3.3+dfsg-1.pgdg80+1 RUN apt-get update \ && apt-get install -y --no-install-recommends \ postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR=$POSTGIS_VERSION \ postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR-scripts=$POSTGIS_VERSION \ - postgis=$POSTGIS_VERSION \ + postgis\ && rm -rf /var/lib/apt/lists/* RUN mkdir -p /docker-entrypoint-initdb.d diff --git a/9.6-2.3/README.md b/9.6-2.3/README.md index efdee8cc..feb4ea09 100644 --- a/9.6-2.3/README.md +++ b/9.6-2.3/README.md @@ -2,7 +2,7 @@ [![Build Status](https://travis-ci.org/appropriate/docker-postgis.svg)](https://travis-ci.org/appropriate/docker-postgis) [![Join the chat at https://gitter.im/appropriate/docker-postgis](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/appropriate/docker-postgis?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -The `mdillon/postgis` image provides a Docker container running Postgres 9 with [PostGIS 2.3](http://postgis.net/) installed. This image is based on the official [`postgres`](https://registry.hub.docker.com/_/postgres/) image and provides variants for each version of Postgres 9 supported by the base image (9.2-9.6). +The `mdillon/postgis` image provides a Docker container running Postgres 9 with [PostGIS 2.3](http://postgis.net/) installed, or Postgres 10 with [PostGIS 2.4](http://postgis.net/) installed. This image is based on the official [`postgres`](https://registry.hub.docker.com/_/postgres/) image and provides variants for each version of Postgres 9 supported by the base image (9.2-9.6) and Postgres 10. This image ensures that the default database created by the parent `postgres` image will have the following extensions installed: diff --git a/9.6-2.3/alpine/Dockerfile b/9.6-2.3/alpine/Dockerfile index 55f5f07a..0192cd1a 100644 --- a/9.6-2.3/alpine/Dockerfile +++ b/9.6-2.3/alpine/Dockerfile @@ -1,8 +1,8 @@ FROM postgres:9.6-alpine MAINTAINER Régis Belson -ENV POSTGIS_VERSION 2.3.2 -ENV POSTGIS_SHA256 7e82c6994acc80c9f6ea57c0c4a1e0f9372c9fa314c9da148486f395bd1dced9 +ENV POSTGIS_VERSION 2.3.3 +ENV POSTGIS_SHA256 3403d5635b4b86c90f6a225a366a515c6bc734d1bad625c7df4e8c6fde7e8588 RUN set -ex \ \ diff --git a/9.6-2.4/Dockerfile b/9.6-2.4/Dockerfile new file mode 100644 index 00000000..7ab717a1 --- /dev/null +++ b/9.6-2.4/Dockerfile @@ -0,0 +1,17 @@ +FROM postgres:9.6 +MAINTAINER Mike Dillon + +ENV POSTGIS_MAJOR 2.4 +ENV POSTGIS_VERSION 2.4.0+dfsg-1.pgdg80+1 + +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR=$POSTGIS_VERSION \ + postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR-scripts=$POSTGIS_VERSION \ + postgis\ + && rm -rf /var/lib/apt/lists/* + +RUN mkdir -p /docker-entrypoint-initdb.d +COPY ./initdb-postgis.sh /docker-entrypoint-initdb.d/postgis.sh +COPY ./update-postgis.sh /usr/local/bin + diff --git a/9.6-2.4/README.md b/9.6-2.4/README.md new file mode 100644 index 00000000..feb4ea09 --- /dev/null +++ b/9.6-2.4/README.md @@ -0,0 +1,51 @@ +# mdillon/postgis + +[![Build Status](https://travis-ci.org/appropriate/docker-postgis.svg)](https://travis-ci.org/appropriate/docker-postgis) [![Join the chat at https://gitter.im/appropriate/docker-postgis](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/appropriate/docker-postgis?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) + +The `mdillon/postgis` image provides a Docker container running Postgres 9 with [PostGIS 2.3](http://postgis.net/) installed, or Postgres 10 with [PostGIS 2.4](http://postgis.net/) installed. This image is based on the official [`postgres`](https://registry.hub.docker.com/_/postgres/) image and provides variants for each version of Postgres 9 supported by the base image (9.2-9.6) and Postgres 10. + +This image ensures that the default database created by the parent `postgres` image will have the following extensions installed: + +* `postgis` +* `postgis_topology` +* `fuzzystrmatch` +* `postgis_tiger_geocoder` + +Unless `-e POSTGRES_DB` is passed to the container at startup time, this database will be named after the admin user (either `postgres` or the user specified with `-e POSTGRES_USER`). If you would prefer to use the older template database mechanism for enabling PostGIS, the image also provides a PostGIS-enabled template database called `template_postgis`. + +## Usage + +In order to run a basic container capable of serving a PostGIS-enabled database, start a container as follows: + + docker run --name some-postgis -e POSTGRES_PASSWORD=mysecretpassword -d mdillon/postgis + +For more detailed instructions about how to start and control your Postgres container, see the documentation for the `postgres` image [here](https://registry.hub.docker.com/_/postgres/). + +Once you have started a database container, you can then connect to the database as follows: + + docker run -it --link some-postgis:postgres --rm postgres \ + sh -c 'exec psql -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U postgres' + +See [the PostGIS documentation](http://postgis.net/docs/postgis_installation.html#create_new_db_extensions) for more details on your options for creating and using a spatially-enabled database. + +## Known Issues / Errors + +When You encouter errors due to PostGIS update `OperationalError: could not access file "$libdir/postgis-X.X`, run: + +`docker exec some-postgis update-postgis.sh` + +It will update to Your newest PostGIS. Update is idempotent, so it won't hurt when You run it more than once, You will get notification like: + +``` +Updating PostGIS extensions template_postgis to X.X.X +NOTICE: version "X.X.X" of extension "postgis" is already installed +NOTICE: version "X.X.X" of extension "postgis_topology" is already installed +NOTICE: version "X.X.X" of extension "postgis_tiger_geocoder" is already installed +ALTER EXTENSION +Updating PostGIS extensions docker to X.X.X +NOTICE: version "X.X.X" of extension "postgis" is already installed +NOTICE: version "X.X.X" of extension "postgis_topology" is already installed +NOTICE: version "X.X.X" of extension "postgis_tiger_geocoder" is already installed +ALTER EXTENSION +``` + diff --git a/9.6-2.4/initdb-postgis.sh b/9.6-2.4/initdb-postgis.sh new file mode 100755 index 00000000..43012885 --- /dev/null +++ b/9.6-2.4/initdb-postgis.sh @@ -0,0 +1,23 @@ +#!/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; +UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template_postgis'; +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 diff --git a/9.6-2.4/update-postgis.sh b/9.6-2.4/update-postgis.sh new file mode 100755 index 00000000..5d1088f2 --- /dev/null +++ b/9.6-2.4/update-postgis.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +set -e + +# Perform all actions as $POSTGRES_USER +export PGUSER="$POSTGRES_USER" + +POSTGIS_VERSION="${POSTGIS_VERSION%%+*}" + +# Load PostGIS into both template_database and $POSTGRES_DB +for DB in template_postgis "$POSTGRES_DB"; do + echo "Updating PostGIS extensions $DB to $POSTGIS_VERSION" + psql --dbname="$DB" -c " + -- Upgrade PostGIS (includes raster) + ALTER EXTENSION postgis UPDATE TO '$POSTGIS_VERSION'; + -- Upgrade Topology + ALTER EXTENSION postgis_topology UPDATE TO '$POSTGIS_VERSION'; + -- Upgrade US Tiger Geocoder + ALTER EXTENSION postgis_tiger_geocoder UPDATE TO '$POSTGIS_VERSION'; + " +done diff --git a/Dockerfile.template b/Dockerfile.template index e5b66120..a6c4eab1 100644 --- a/Dockerfile.template +++ b/Dockerfile.template @@ -8,7 +8,7 @@ RUN apt-get update \ && apt-get install -y --no-install-recommends \ postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR=$POSTGIS_VERSION \ postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR-scripts=$POSTGIS_VERSION \ - postgis=$POSTGIS_VERSION \ + postgis\ && rm -rf /var/lib/apt/lists/* RUN mkdir -p /docker-entrypoint-initdb.d diff --git a/README.md b/README.md index efdee8cc..feb4ea09 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Build Status](https://travis-ci.org/appropriate/docker-postgis.svg)](https://travis-ci.org/appropriate/docker-postgis) [![Join the chat at https://gitter.im/appropriate/docker-postgis](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/appropriate/docker-postgis?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -The `mdillon/postgis` image provides a Docker container running Postgres 9 with [PostGIS 2.3](http://postgis.net/) installed. This image is based on the official [`postgres`](https://registry.hub.docker.com/_/postgres/) image and provides variants for each version of Postgres 9 supported by the base image (9.2-9.6). +The `mdillon/postgis` image provides a Docker container running Postgres 9 with [PostGIS 2.3](http://postgis.net/) installed, or Postgres 10 with [PostGIS 2.4](http://postgis.net/) installed. This image is based on the official [`postgres`](https://registry.hub.docker.com/_/postgres/) image and provides variants for each version of Postgres 9 supported by the base image (9.2-9.6) and Postgres 10. This image ensures that the default database created by the parent `postgres` image will have the following extensions installed: diff --git a/update.sh b/update.sh index 9386c64b..c60d16a1 100755 --- a/update.sh +++ b/update.sh @@ -10,13 +10,24 @@ if [ ${#versions[@]} -eq 0 ]; then fi versions=( "${versions[@]%/Dockerfile}" ) -packagesUrl='http://apt.postgresql.org/pub/repos/apt/dists/jessie-pgdg/main/binary-amd64/Packages' -packages="$(echo "$packagesUrl" | sed -r 's/[^a-zA-Z.-]+/-/g')" -curl -sSL "${packagesUrl}.bz2" | bunzip2 > "$packages" +packagesUrlJessie='http://apt.postgresql.org/pub/repos/apt/dists/jessie-pgdg/main/binary-amd64/Packages' +packagesJessie="$(echo "$packagesUrlJessie" | sed -r 's/[^a-zA-Z.-]+/-/g')" +curl -sSL "${packagesUrlJessie}.bz2" | bunzip2 > "$packagesJessie" + +packagesUrlStretch='http://apt.postgresql.org/pub/repos/apt/dists/stretch-pgdg/main/binary-amd64/Packages' +packagesStretch="$(echo "$packagesUrlStretch" | sed -r 's/[^a-zA-Z.-]+/-/g')" +curl -sSL "${packagesUrlStretch}.bz2" | bunzip2 > "$packagesStretch" travisEnv= for version in "${versions[@]}"; do IFS=- read pg_major postgis_major <<< "$version" + if [[ $pg_major = 9* ]]; then + packages="$packagesJessie" + else + packages="$packagesStretch" + fi + + fullVersion="$(grep -m1 -A10 "^Package: postgresql-$pg_major-postgis-$postgis_major\$" "$packages" | grep -m1 '^Version: ' | cut -d' ' -f2)" [ -z "$fullVersion" ] && { echo >&2 "Unable to find package for PostGIS $postgis_major on Postgres $pg_major"; exit 1; } ( @@ -46,4 +57,5 @@ done travis="$(awk -v 'RS=\n\n' '$1 == "env:" { $0 = "env:'"$travisEnv"'" } { printf "%s%s", $0, RS }' .travis.yml)" echo "$travis" > .travis.yml -rm "$packages" +rm "$packagesJessie" +rm "$packagesStretch" \ No newline at end of file