A simple docker container that runs PostGIS
Visit our page on the docker hub at: https://hub.docker.com/r/corylabiosphere/postgis-plr/
There are a number of other docker postgis containers out there. This one differentiates itself by:
- connections are restricted to the docker subnet
- a default database 'gis' is created for you so you can use this container 'out of the box' when it runs with e.g. QGIS
- Ability to create multiple database when you spin the database
- Enable multiple extensions in the database when setting it up, plr included
- Enable R statistical language with GIS modules preinstalled
There is a nice 'from scratch' tutorial on using this docker image on Alex Urquhart's blog here - if you are just getting started with docker, PostGIS and QGIS, we really recommend that you use it.
The following convention is used for tagging the images we build:
corylabiosphere/postgis-plr:[postgres_version]-[postgis-version]-[r-version]
So for example:
corylabiosphere/postgis-plr:9.6-2.4-3.2
Provides PostgreSQL 9.6, PostGIS 2.4, R 3.2
Note: We highly recommend that you use tagged versions because successive minor versions of PostgreSQL write their database clusters into different database directories - which will cause your database to appear to be empty if you are using persistent volumes for your database storage.
There are various ways to get the image onto your system:
The preferred way (but using most bandwidth for the initial image) is to get our docker trusted build like this:
docker pull corylabiosphere/postgis-plr
To build the image yourself without apt-cacher (also consumes more bandwidth since deb packages need to be refetched each time you build) do:
docker build -t corylabiosphere/postgis-plr git://github.com/Shappiro/docker-postgis-plr
To create a running container do:
sudo docker run --name "postgis" -p localhort:5433 -d -t corylabiosphere/postgis-plr
Note: Default port is 5433, so this can cause potential conflicts if a database cluster is already settled in your system with that port. Note that this can be changed at docker creation time through the environment variable * -e POSTGRES_PORT*.
You can also use the following environment variables to pass a user name, password and/or default database name(or multiple databases coma separated).
- -e POSTGRES_USER=
- -e POSTGRES_PASS=
- -e POSTGRES_DBNAME=
- -e POSTGRES_PORT=
- -e POSTGRES_MULTIPLE_EXTENSIONS=postgis,hstore,postgis_topology # You can pass as many extensions as you need.
These will be used to create a new superuser with your preferred credentials. If these are not specified then the postgresql user is set to 'docker' with password 'docker'.
You can open up the PG port by using the following environment variable. By default the container will allow connections only from the docker private subnet.
- -e ALLOW_IP_RANGE=<0.0.0.0/0> By default t
Postgres conf is setup to listen to all connections and if a user needs to restrict which IP address PostgreSQL listens to you can define it with the following environment variable. The default is set to listen to all connections.
- -e IP_LIST=<*>
Connect with psql (make sure you first install postgresql client tools on your host / client):
psql -h localhost -U docker -p 5433 -l
Note: Default postgresql user is 'docker' with password 'docker'.
You can then go on to use any normal postgresql commands against the container.
Docker volumes can be used to persist your data.
mkdir -p ~/postgres_data
docker run -d -v $HOME/postgres_data:/var/lib/postgresql corylabiosphere/postgis-plr`
You need to ensure the postgres_data
directory has sufficient permissions
for the docker process to read / write it.
Tim Sutton ([email protected]) Gavin Fleming ([email protected]) Risky Maulana ([email protected]) Admire Nyakudya ([email protected]) Aaron Iemma ([email protected]) June 2019