Graphhopper Docker container

08:36 , , 0 Comments

In my most recent project, travel planning tool, 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

Take a look on 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 \
$ 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:


The last thing which was needed is ability to override JAVA_OPTS, especially memory settings. To do that, just create 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/
JAVA_OPTS="-Xms128m -Xmx128m -XX:MaxPermSize=64m -server -Djava.awt.headless=true -Xconcurrentio"

Stanisław Ogórkis

Software engineer specializing in delivering highly interactive web applications and complex enterprise systems.