by: Just van den Broecke - justb4 (@) gmail.com
This example uses Docker Compose with pg_tileserv
and PostGIS (v3) Docker Images.
Run with these steps: Build, Run, Load Vector Data, and run the
standard web-viewer examples like Leaflet.
We use a docker-compose.yml file with environment settings in
pg_tileserv.env and pg.env for pg_tileserv
and the PG database.
docker-compose build
This should build the latest Alpine-based Docker Image for pg_tileserv
.
docker-compose up
NB on the first run the PostGIS Docker Image is downloaded and the DB initialized. pg_tileserv
may not be able to connect.
In that case stop the Docker Compose process (ctrl-C) and run again. In another terminal window test
if pg_tileserv
Container is at least running:
curl -v http://localhost:7800/public.ne_50m_admin_0_countries/2/2/3.pbf
.
You will see an regular error message like "Unable to get layer 'public.ne_50m_admin_0_countries" as no data is yet in the database.
We load all sample data using shp2pgsql
and psql
within the PostGIS Docker Container, so we don't need to install any Postgres/PostGIS tools locally.
The ./data
dir is mapped into the Docker Container at /work
.
First Download these files into the ./data
subdir:
- Natural Earth Admin 0 Countries.
- fire hydrant data"
Unzip these two zip-files within the ./data
subdir.
To run also the OpenLayers Voronoi example using Docker, we apply
the OpenLayers Function-click SQL. This example demonstrates the powerful "Function" capability of pg_tileserv
,
creating the public.hydrants_delaunay()
function in your database.
To load the two datasets and Function SQL, use the load-data.sh helper script
./load-data.sh
- restart the docker-compose stack
The above data-loading script exec
s the running PostGIS Docker Container pg_tileserv_db
as for example:
docker-compose exec pg_tileserv_db sh -c "shp2pgsql -d -D -s 4326 /work/ne_50m_admin_0_countries.shp | psql -U tileserv -d tileserv"
As the pg_tileserv
container has a Docker port-mapping to localhost:7800, you can use the standard HTML examples locally in your browser.
In a real-world application you would run these in a web-server container like nginx
or Apache httpd
.
See Leaflet, MapBox and OpenLayers. And the openlayers-function-click.html for the Voronoi Function example.
If something goes wrong along the way, or you want a clean restart, run this script:
./cleanup.sh
This will delete dangling Docker Containers and and Images and the DB volume