Graphhopper Docker container

08:36 , , 0 Comments

In my most recent project, travel planning tool tribear.com, we had to optimize routes for independent travelers. After evaluating several alternatives we decided to go with open source routing engine GraphHopper.

GraphHopper can be used in several ways: webapp, android lib or regular java lib. We decided to use webapp deployment and call REST API to calculate routes between points. Moreover we wanted to run multiple instances of GraphHopper for each city/region. This way we do not need to have one huge GraphHopper instance for whole world (it needs over 16GB of memory), but separate small ones.

After playing a bit with docker project it seemed to be a perfect fit for automating configuration. I wanted to have simple image with java and GraphHopper run time with data directory mounted to host. You can find my dockerfile in github repo.

To run GraphHopper web app you need to provide map data by passing .pbf  file to program args. In my docker image, file with pbf extension is picked up from directory mounted to host directory. So first step is creating directory on your host and downloading .pbf file for particular region.

$ mkdir -p ~/private/graphhopper-data/berlin/
$ cd ~/private/graphhopper-data/berlin/
$ wget http://download.geofabrik.de/europe/germany/berlin-latest.osm.pbf

Take a look on config.properties. You can customize your GraphHopper instance here (for instance change routing from default car to bike). When you are ready, build image and run new docker container:

$ sudo docker build -t sogorkis/graphhopper .
$ sudo docker run \
      -d \
      --name=graphhopper-berlin \
      -v /home/stanislaw/private/graphhopper-data/berlin/:/data \
      -p 8990:8989 \
      sogorkis/graphhopper \
      /graphhopper/start.sh
$ sudo docker logs -f graphhopper-berlin
...
2014-10-04 11:21:30,110 [main] INFO  graphhopper.http.DefaultModule - loaded graph at:/data/berlin-latest.osm-gh, source:/data/berlin-latest.osm.pbf, acceptWay:car, class:LevelGraphStorage
2014-10-04 11:21:30,611 [main] INFO  graphhopper.http.GHServer - Started server at HTTP 8989

Please note that first run might take some time as GraphHopper needs to processes .pbf file and create additional work files. Tail logs till you see that server is started and run following url in your browser:

http://localhost:8990/?point=52.516534%2C13.381568&point=52.519877%2C13.40493&locale=en-US



The last thing which was needed is ability to override JAVA_OPTS, especially memory settings. To do that, just create env.sh file in mounted directory. For instance to reduce max heap size for graphhopper-berlin image, create following file:

$ cat /home/stanislaw/private/graphhopper-data/berlin/env.sh
JAVA_OPTS="-Xms128m -Xmx128m -XX:MaxPermSize=64m -Djava.net.preferIPv4Stack=true -server -Djava.awt.headless=true -Xconcurrentio"

0 comments: