Skip to content

Instantly share code, notes, and snippets.

@AlexandraKapp
Last active September 30, 2024 13:54
Show Gist options
  • Save AlexandraKapp/e0eee2beacc93e765113aff43ec77789 to your computer and use it in GitHub Desktop.
Save AlexandraKapp/e0eee2beacc93e765113aff43ec77789 to your computer and use it in GitHub Desktop.
How to set up your own OSRM backend with Docker on Windows

How to set up your own OSRM backend with Docker on Windows

The OSRM docker quick start provides a great explanation on how to set up the container: https://hub.docker.com/r/osrm/osrm-backend/

Yet - for Docker on Windows minor changes were necessary for me (otherwise I'd get "File not found" or "Permission" errors).

This is how it worked for me:

1. Pull the image

docker pull osrm/osrm-backend

2. Download OpenStreetMap extract

Download OpenStreetMap extracts for example from Geofabrik

e.g.

Save the OpenStreetMap extract in a folder you can access from the shared drive: e.g. if your shared drive is "C:" place it in a folder "C:/docker"

shared folder img

3. Pre-process extract

Pre-process the extract and start a routing engine HTTP server on port 5000.

Depending on what kind of routing you want to use, choose the profile accordingly:

  • car: car.lua

  • walking: foot.lua

  • bike: bicycle.lua

    docker run -t -v c:/docker:/data osrm/osrm-backend osrm-extract -p /opt/PROFILE.lua /data/CITY-latest.osm.pbf

So for car rides in Berlin use:

docker run -t -v c:/docker:/data osrm/osrm-backend osrm-extract -p /opt/car.lua /data/berlin-latest.osm.pbf

Then run:

docker run -t -v c:/docker:/data osrm/osrm-backend osrm-partition /data/berlin-latest.osrm
docker run -t -v c:/docker:/data osrm/osrm-backend osrm-customize /data/berlin-latest.osrm

4. Start the Routing Engine

docker run --name osrm -t -i -p 5000:5000 -v c:/docker:/data osrm/osrm-backend osrm-routed --algorithm mld /data/berlin-latest.osrm

Then the docker container should be running on http://127.0.0.1:5000/

Test request:

curl "http://127.0.0.1:5000/route/v1/driving/13.388860,52.517037;13.385983,52.496891?steps=true"

To get the engine started a second time when you pick up your work, only the last container needs to be started again. If you named it (with the flag --name osrm), you can run:

docker start osrm

Futher useful links:

@VDU8
Copy link

VDU8 commented Jan 25, 2024

@AlexandraKapp What if I want curl "/foot/" or "/bicycle/" profiles how do I get that? I am trying to display the routes on a webpage this deafults to driving I did download bicycle and foot profiles lua's how do I use that to display routes all three of them at once

@piiskop
Copy link

piiskop commented Jun 24, 2024

This method does not seem to work for bicycle and foot routes. These docker images will still run at the port 5000 although I wrote "5300:5300" and once making a query to 5300, there would be no connection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment