Code Monkey home page Code Monkey logo

mapserver-docker's Introduction

Mapserver docker

GitHub license GitHub release Docker Pulls

Mapserver Docker image using lighttpd build with GDAL/OGR, PostGIS to serve out WMS, WFS and WCS services.

TL;DR

docker build

docker build -t pdok/mapserver .

docker run wms

docker run -e MS_MAPFILE=/srv/data/example.map -e SERVICE_TYPE=WMS  --rm -d \
            -p 80:80 --name mapserver-example -v `pwd`/example:/srv/data pdok/mapserver 

docker run wfs

docker run -e MS_MAPFILE=/srv/data/example.map -e SERVICE_TYPE=WFS  --rm -d \
            -p 80:80 --name mapserver-example -v `pwd`/example:/srv/data pdok/mapserver 

docker stop

docker stop mapserver-example

Introduction

This project aims to fulfill two needs:

  1. create OGC services that are deployable on a scalable infrastructure.
  2. create a useable Docker base image.

Fulfilling the first need the main purpose is to create an Docker base image that can be run on a platform like Kubernetes.

Regarding the second need, finding a usable Mapserver Docker image is a challenge. Most images expose the &map=... QUERY_STRING in the GetCapabilities, don't run in FastCGI and are based on Apache.

What will it do

It will create an Mapserver application that runs through lighttpd. With lua scripting the map=... QUERY_STRING is filter from incoming request. In other words the used Mapfile can only be set with an ENV.

The included EPSG file containing the projection parameters only contains a small set of available EPSG code, namely the once used by our organization. If one wants to use additional EPSG projections one can overwrite this file.

Docker image

The Docker image contains 2 stages:

  1. builder
  2. service

builder

The builder stage compiles Mapserver. The Dockerfile contains all the available Mapserver build option explicitly, so it is clear which options are enabled and disabled.

service

The service stage copies the Mapserver application, build in the first stage to the service stage, and configures lighttpd

Usage

Build

docker build -t pdok/mapserver .

For a specific Dutch version which includes a specific (and smaller) epsg file and necessary grid corrections files.

docker build -t pdok/mapserver:nl -f Dockerfile.NL .

Run

This image can be run straight from the command-line. A volume needs to be mounted on the container directory /srv/data. The mounted volume needs to contain a mapserver *.map file that matches the MS_MAPFILE env var.

docker run \
   --rm -d \
   -e MS_MAPFILE=/srv/data/example.map \
   -p 80:80 \
   --name mapserver-example \
   -v `pwd`/example:/srv/data \
   pdok/mapserver

Running the example above will create a service on the url http://localhost/mapserver?REQUEST=GetCapabilities&SERVICE=WMS that will accept something like a (GetMap request).

The environment variables that can be set are the following:

  • DEBUG
  • MIN_PROCS
  • MAX_PROCS
  • MAX_LOAD_PER_PROC
  • IDLE_TIMEOUT
  • MS_MAPFILE
  • PROJ_LIB

The environment variables, with the exception of MS_MAPFILE have a default value set in the Dockerfile.

The GDAL PROJ_LIB env var is default set with the value /usr/share/proj. For performance reasons one would like to set a custom PROJ_LIB containing a minimum of available EPSG codes. This can be done with the mentioned PROJ_LIB env var.

docker run \
   --rm -d \
   -p 80:80 \
   --name mapserver-run-example \
   -v `pwd`/example:/srv/data \
   -e DEBUG=0 \
   -e MIN_PROCS=1 \
   -e MAX_PROCS=3 \
   -e MAX_LOAD_PER_PROC=4 \
   -e IDLE_TIMEOUT=20 \
   -e MS_MAPFILE=/srv/data/example.map \
   pdok/mapserver

Projections

Altering the proj file is done for different reasons, adding custom projections or removing 'unused' ones for better performance. This can be done in a couple of ways through this setup.

base image

The best example for this is the Dockerfile.NL in this repository. This Dockerfile uses the main Dockerfile as a base image copies specific geodetic grid files and overwrites the default espg with a tuned one for the Netherlands.

A good resource for these geodetic files is the PROJ.org Datumgrid CDN.

volume

Another option is to create a proj file (like in the nl folder) and mount this to the container and set the PROJ_LIB env var to that location by adding the following parameters to the docker command:

-e PROJ_LIB=/my-custom-proj-dir \
-v `pwd`/path/to/proj/dir:/my-custom-proj-dir \

Example

When starting the container it will create a WMS & WFS service on the accespoint: http://localhost/mapserver.

Example requests

WMS

Example requests when the container is run as WMS service

WFS

Example requests when the container is run as WFS service

Misc

Why Lighttpd

In our previous configurations we would run NGINX, while this is a good web service and has a lot of configuration options, it runs with multiple processes. There for we needed supervisord for managing this, whereas lighttpd runs as a single process. Also all the routing configuration options aren't needed, because that is handled by the infrastructure/platform, like Kubernetes. If one would like to configure some simple routing is still can be done in the lighttpd.conf.

Used examples

mapserver-docker's People

Contributors

arbakker avatar copierrj avatar geppyz avatar gerdos82 avatar kad-jagtt avatar robbert2407 avatar roelvandenberg avatar woutervisscher avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mapserver-docker's Issues

Restricted use of port 80

Some organization are restricting the use of port 80.

Is there a way to configure a different port to use on localhost?

thanks.

Contact info

Thanks for sharing. The email in the Dockerfile doesn't work, where can I contact someone regarding a very minor security issue?

mention of 900913 in example.map throws warning on logs

for the example mapfile provided the logs show this error:

2022-02-09 11:47:43: (mod_fastcgi.c.421) FastCGI-stderr: msProcessProjection(): Projection library error. proj error "no arguments in initialization list" for "init=epsg:900913"

probably related to mention of 900913 in

"ows_srs" "EPSG:4326 EPSG:3857 EPSG:4258 EPSG:900913 CRS:84"

suggest to add the projection to poj, because it is generally used, however it would be better to use epsg:3857

403 forbidden response

Hi,

Trying to run the example.map setup on k8s, but I'm getting a 403 response:

10.233.103.117 mapserver-2637-main.kube-idev.bgslcdevops.test - [12/Apr/2023:11:02:06 +0200] "GET /?REQUEST=GetCapabilities&SERVICE=WMS HTTP/1.1" 403 341 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
10.233.103.117 mapserver-2637-main.kube-idev.bgslcdevops.test - [12/Apr/2023:11:02:46 +0200] "GET /?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&BBOX=50,2.423859315589366403,54,9&CRS=EPSG:4326&WIDTH=1648&HEIGHT=1002&LAYERS=example&STYLES=&FORMAT=image/png&DPI=96&MAP_RESOLUTION=96&FORMAT_OPTIONS=dpi:96&TRANSPARENT=TRUE HTTP/1.1" 403 341 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"

My dockerfile looks like:

FROM pdok/mapserver:7.6.4-patch-5-2

ENV MS_MAPFILE=/srv/data/example.map
ENV SERVICE_TYPE=WMS  

COPY ./content/ /srv/data

EXPOSE 80

content contains the 3 example files

Do you have any suggestions?

docker build -t pdok/mapserver . does not work

When I run the command, I get the following result:

$ sudo docker build -t pdok/mapserver .
[+] Building 0.1s (1/1) FINISHED                                                                                                docker:default
 => [internal] load build definition from Dockerfile                                                                  0.1s
 => => transferring dockerfile: 2B                                                                                             0.0s
ERROR: failed to solve: failed to read dockerfile: open Dockerfile: no such file or directory

If I create the dockerfile manually and try again, I get the following:

$ sudo docker build -t pdok/mapserver .
[+] Building 2.0s (20/22)                                                                                                                                  docker:default
 => [internal] load build definition from Dockerfile                                                                                                                 0.0s
 => => transferring dockerfile: 4.59kB                                                                                                                               0.0s
 => [internal] load metadata for docker.io/pdok/lighttpd:1.4.67                                                                                                      1.7s
 => [internal] load metadata for docker.io/library/debian:buster                                                                                                     1.9s
 => [internal] load .dockerignore                                                                                                                                    0.0s
 => => transferring context: 2B                                                                                                                                      0.0s
 => CANCELED [builder 1/8] FROM docker.io/library/debian:buster@sha256:bce46a1c39574f98c845df4a5acc6c70c211df5a6182e428c1155c33317d4920                              0.0s
 => => resolve docker.io/library/debian:buster@sha256:bce46a1c39574f98c845df4a5acc6c70c211df5a6182e428c1155c33317d4920                                               0.0s
 => => sha256:bce46a1c39574f98c845df4a5acc6c70c211df5a6182e428c1155c33317d4920 984B / 984B                                                                           0.0s
 => => sha256:255eec9d157d35e00a81a45f1e958fd19437d504139e8eb4ea6cc380ea741ed4 529B / 529B                                                                           0.0s
 => => sha256:c94cce4c115de0a1328304e8981a68cf4b4b657ef6dbda52e188ac651368d603 1.46kB / 1.46kB                                                                       0.0s
 => [internal] load build context                                                                                                                                    0.0s
 => => transferring context: 2B                                                                                                                                      0.0s
 => CANCELED [service 1/9] FROM docker.io/pdok/lighttpd:1.4.67@sha256:c8a3ec50dc964f67959f8652880c66b696c2421e1ca8d7b48a5b9ee87226e9c2                               0.0s
 => => resolve docker.io/pdok/lighttpd:1.4.67@sha256:c8a3ec50dc964f67959f8652880c66b696c2421e1ca8d7b48a5b9ee87226e9c2                                                0.0s
 => => sha256:c8a3ec50dc964f67959f8652880c66b696c2421e1ca8d7b48a5b9ee87226e9c2 856B / 856B                                                                           0.0s
 => => sha256:581277dd8a663b04d00e7c45943037917abe2a6342a1ea804d09b0d9dfa5bb97 2.00kB / 2.00kB                                                                       0.0s
 => CACHED [builder 2/8] RUN apt-get -y update &&     apt-get install -y --no-install-recommends         ca-certificates         gettext         xz-utils         c  0.0s
 => CACHED [builder 3/8] RUN update-locale LANG=C.UTF-8                                                                                                              0.0s
 => CACHED [builder 4/8] RUN cd /tmp &&         wget https://github.com/harfbuzz/harfbuzz/releases/download/2.8.2/harfbuzz-2.8.2.tar.xz &&         tar xJf harfbuzz  0.0s
 => CACHED [builder 5/8] RUN apt-get -y update &&     apt-get install -y --no-install-recommends         libcurl4-gnutls-dev         libfribidi-dev         libgif-  0.0s
 => CACHED [builder 6/8] RUN apt-get -y update --fix-missing                                                                                                         0.0s
 => CACHED [builder 7/8] RUN git clone --single-branch -b pdok-7-6-4-patch-5 https://github.com/pdok/mapserver/ /usr/local/src/mapserver                             0.0s
 => CACHED [builder 8/8] RUN mkdir /usr/local/src/mapserver/build &&     cd /usr/local/src/mapserver/build &&     cmake ../         -DWITH_PROJ=ON         -DWITH_K  0.0s
 => CACHED [service 2/9] COPY --from=builder /usr/local/bin /usr/local/bin                                                                                           0.0s
 => CACHED [service 3/9] COPY --from=builder /usr/local/lib /usr/local/lib                                                                                           0.0s
 => CACHED [service 4/9] RUN apt-get -y update &&     apt-get install -y --no-install-recommends         ca-certificates         libpng16-16         python-cairocf  0.0s
 => ERROR [service 5/9] ADD config/lighttpd.conf /srv/mapserver/config/lighttpd.conf                                                                                 0.0s
 => ERROR [service 6/9] ADD config/include.conf /srv/mapserver/config/include.conf                                                                                   0.0s
 => ERROR [service 7/9] ADD config/request.lua /srv/mapserver/config/request.lua                                                                                     0.0s
------
 > [service 5/9] ADD config/lighttpd.conf /srv/mapserver/config/lighttpd.conf:
------
------
 > [service 6/9] ADD config/include.conf /srv/mapserver/config/include.conf:
------
------
 > [service 7/9] ADD config/request.lua /srv/mapserver/config/request.lua:
------
Dockerfile:160
--------------------
 158 |     ADD config/lighttpd.conf /srv/mapserver/config/lighttpd.conf
 159 |     ADD config/include.conf /srv/mapserver/config/include.conf
 160 | >>> ADD config/request.lua /srv/mapserver/config/request.lua
 161 |
 162 |     RUN chmod o+x /usr/local/bin/mapserv
--------------------
ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref b2de52a4-9d6c-4e4d-95f8-eb49f008296d::ehnctf60lykflhwabkjj82a3z: failed to walk /var/lib/docker/tmp/buildkit-mount3659353059/config: lstat /var/lib/docker/tmp/buildkit-mount3659353059/config: no such file or directory


Please advise.

Running the example in remote server

Hi,

I have run the example.map in local and it works well. The problem is when i try to run it in a remote server. I go to http://${HOST}/mapserver?REQUEST=GetCapabilities&SERVICE=WMS and it returns a 403 Error response or a file with "{}". Perhaps the problem is caused by lighttpd.

Do you have any suggestions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.