--- breaks: false # False means NOT to render line breaks as hard line breaks. --- # osrm-docker-toolbox [![hackmd-github-sync-badge](https://hackmd.io/R-DHXk_HRGGzvLBTlUHcHQ/badge)](https://hackmd.io/R-DHXk_HRGGzvLBTlUHcHQ) Files and step-by-step instructions on how to run osrm service on windows using Docker Toolbox. ### Steps 1. https://docs.docker.com/toolbox/toolbox_install_windows/ Download Docker Toolbox from the link above, install and run according to the instructions given. 2. Once the docker terminal is up and running, type in terminal: - `docker pull osrm/osrm-backend` This will pull the latest image of osrm. - `docker images` To list out pulled images. 3. Download map file from https://download.geofabrik.de/ - For Malaysia map which we're gonna use later https://download.geofabrik.de/asia/malaysia-singapore-brunei-latest.osm.pbf - In order for the virtual machine to be able to read the map file on the host machine, we need to set up a shared folder. There is a default shared folder `C:\Users`, but we're going to setup a custom one instead. - Run `Oracle VM VirtualBox` and right-click on the `default` machine that's running, then click `Settings`. - Go to `Shared Folders` and add the folder path to the map file that we've just downloaded. - `Folder Path` points to the folder that holds the map file on the host machine. - `Folder Name` is the name that the virtual machine will use to access the folder, we still have to do mounting with the name later. - Say, if we put the map file in `D:\data\`, the configuration will be as shown below: ![](https://i.imgur.com/5dRXo4J.png) 4. Mounting Shared Folder, type in terminal: - `docker-machine ssh` to access the virtual machine's terminal, then `cd` to the directory where we're gonna build our files. - `mkdir osrm` to make a new directory named `osrm`. For this example, our full file path will be `/home/docker/osrm`. - `sudo mount -t vboxsf -o uid=1000,gid=50 Map /home/docker/osrm` to mount the shared folder where `Map` is the name that we assigned earlier to the file path on host machine and `/home/docker/osrm` is the mount point. - `cd /home/docker/osrm` and `ls` to check if the files from the host machine are visible on the virtual machine. - `CTRL + D` to exit ssh connection to virtual machine. 5. Extract, Partition and Customise map file if we're using [MLD algorithm to calculate route](https://github.com/Project-OSRM/osrm-backend/wiki/Running-OSRM), type in terminal: ``` docker run -t -v /home/docker/osrm:/osrm/ osrm/osrm-backend osrm-extract -p /opt/car.lua /osrm/malaysia-singapore-brunei-latest.osm.pbf docker run -t -v /home/docker/osrm:/osrm/ osrm/osrm-backend osrm-partition /osrm/malaysia-singapore-brunei-latest.osrm docker run -t -v /home/docker/osrm:/osrm/ osrm/osrm-backend osrm-customize /osrm/malaysia-singapore-brunei-latest.osrm ``` - Note the file paths above, they are the paths to the shared folder on the virtual machine `/home/docker/osrm/` where `osrm` is the new directory we've just created. - The `/osrm/malaysia-singapore-brunei-latest.osm.pbf` refers to `/home/docker/osrm/malaysia-singapore-brunei-latest.osm.pbf` - Also, `osrm/osrm-backend` is the name of the image that we gonna run. Alternatively, to process the map file to utilise [CH algorithm for route calculation](https://github.com/Project-OSRM/osrm-backend/wiki/Running-OSRM), type in terminal: ``` docker run -t -v /home/docker/osrm:/osrm/ osrm/osrm-backend osrm-extract -p /opt/car.lua /osrm/malaysia-singapore-brunei-latest.osm.pbf docker run -t -v /home/docker/osrm:/osrm/ osrm/osrm-backend osrm-contract /osrm/malaysia-singapore-brunei-latest.osrm ``` - Note that if you want to build the files for 2 algorithms, you need to only do `osrm-extract` once. 6. Run osrm docker image with port mapping of 5000 in container to 6000 on Docker host, type in terminal: For `MLD algorithm`: ``` docker run -t -i -p 6000:5000 -v /home/docker/osrm:/osrm/ osrm/osrm-backend osrm-routed --algorithm mld /osrm/malaysia-singapore-brunei-latest.osrm ``` For `CH algorithm`: ``` docker run -t -i -p 6000:5000 -v /home/docker/osrm:/osrm/ osrm/osrm-backend osrm-routed --algorithm ch /osrm/malaysia-singapore-brunei-latest.osrm ``` - Take note that Virtualbox will forward container port `5000` to `192.168.99.100:6000` which is the default IP address of Docker Linux virtual machine. - We have to add another port forwarding rule from `192.168.99.100:6000` to `localhost:6000`. - Again, launch `Oracle VM VirtualBox` and right-click on the `default` machine that’s running, then click `Settings`. - Go to `Network` and under `Adapter 1`, click `Port Forwarding`. - Add new rule, setting: | HOST IP | HOST PORT | GUEST PORT | |:---------:|:---------:|:----------:| | 127.0.0.1 | 6000 | 6000 | - The configuration will be as shown below: ![](https://i.imgur.com/oOCWeXQ.png) 7. Test using the following GET request: `http://localhost:6000/table/v1/driving/100.274313,5.332218;100.2759838,5.3306651?sources=1&destinations=0&annotations=duration,distance` - If the response is `Ok` then your osrm server is all set to go.