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:

@tikky
Copy link

tikky commented Jan 12, 2021

great, thank you. I've strugle with linux docker manual and could not convert paths to windows

@gstecca
Copy link

gstecca commented Jan 26, 2021

Thanks for the great posto! I have one question. Can I have more profiles pre-processed in the same docker? In that case which instruction must I repeat for each profile? Thank you!

@SUDSRK
Copy link

SUDSRK commented Feb 3, 2021

Thank You, that was helpful.Can docker service restart itself on restarting the server?

@AlexandraKapp
Copy link
Author

@gstecca @SUDSRK I'm sorry I'm also no expert in docker or OSRM. Maybe ask there?

@do-me
Copy link

do-me commented Oct 11, 2021

If anyone is here for Docker on Windows but under WSL just alter the lines. In my case e.g.:

docker run -t -v C:\Users\do-me\osrm\data:/data osrm/osrm-backend osrm-extract -p /opt/car.lua /data/germany-latest.osm.pbf
docker run -t -v C:\Users\do-me\osrm\data:/data osrm/osrm-backend osrm-partition /data/germany-latest.osrm
docker run -t -v C:\Users\do-me\osrm\data:/data osrm/osrm-backend osrm-customize /data/germany-latest.osrm
docker run --name osrm -t -i -p 5000:5000 -v C:\Users\do-me\osrm\data:/data osrm/osrm-backend osrm-routed --algorithm mld /data/germany-latest.osrm

See this explanation under "shared folders on demand".

@SanktDoshi
Copy link

Very useful.

@simon-vanherck
Copy link

#Issue
I'm trying to pre-process the extracts of the Europe region based on the 'How to' that you wrote here. The procedure osrm-extract just stops without giving any messages.

Here is the log :

C:\WINDOWS\system32>docker run -t -v e:/docker_data/europe:/data osrm/osrm-backend osrm-extract -p /opt/car.lua /data/europe-latest.osm.pbf
[info] Parsed 0 location-dependent features with 0 GeoJSON polygons
[info] Using script /opt/car.lua
[info] Input file: europe-latest.osm.pbf
[info] Profile: car.lua
[info] Threads: 12
[info] Parsing in progress..
[info] input file generated by osmium/1.8.0
[info] timestamp: 2022-06-05T20:21:37Z
[info] Using profile api version 4
[info] Found 3 turn restriction tags:
[info] motorcar
[info] motor_vehicle
[info] vehicle
[info] Parse relations ...
[info] Parse ways and nodes ...
[info] Using profile api version 4
[info] Using profile api version 4
[info] Using profile api version 4
[info] Using profile api version 4
[info] Using profile api version 4
[info] Using profile api version 4
[info] Using profile api version 4
[info] Using profile api version 4
[info] Using profile api version 4
[info] Using profile api version 4
[info] Using profile api version 4
[info] Using profile api version 4
[info] Using profile api version 4

I succefully pre-processed the berlin example and the log looks like this and athe end I get a bunch of files which is not the case for the europe package

C:\WINDOWS\system32>docker run -t -v e:/docker_data/berlin:/data osrm/osrm-backend osrm-extract -p /opt/car.lua /data/berlin-latest.osm.pbf
[info] Parsed 0 location-dependent features with 0 GeoJSON polygons
[info] Using script /opt/car.lua
[info] Input file: berlin-latest.osm.pbf
[info] Profile: car.lua
[info] Threads: 12
[info] Parsing in progress..
[info] input file generated by osmium/1.8.0
[info] timestamp: 2022-06-05T20:21:37Z
[info] Using profile api version 4
[info] Found 3 turn restriction tags:
[info] motorcar
[info] motor_vehicle
[info] vehicle
[info] Parse relations ...
[info] Parse ways and nodes ...
[info] Using profile api version 4
[info] Using profile api version 4
[info] Using profile api version 4
[info] Using profile api version 4
[info] Using profile api version 4
[info] Using profile api version 4
[info] Using profile api version 4
[info] Using profile api version 4
[info] Using profile api version 4
[info] Using profile api version 4
[info] Using profile api version 4
[info] Parsing finished after 4.90077 seconds
[info] Raw input contains 6180692 nodes, 935685 ways, and 1435 relations, 1325 restrictions
[info] Collecting way information on 1325 restrictions...ok, after 0.003266s
[info] Collecting way information on 0 maneuver overrides...ok, after 0.000781s
[info] Sorting used nodes ... ok, after 0.005268s
[info] Erasing duplicate nodes ... ok, after 0.001292s
[info] Sorting all nodes ... ok, after 0.003466s
[info] Building node id map ... ok, after 0.007219s
[info] Confirming/Writing used nodes ... ok, after 1.41599s
[info] Writing barrier nodes ... ok, after 0s
[info] Writing traffic light nodes ... ok, after 0s
[info] Processed 397852 nodes
[info] Sorting edges by start ... ok, after 0.011108s
[info] Setting start coords ... ok, after 0.025661s
[info] Sorting edges by target ... ok, after 0.0106s
[info] Computing edge weights ... ok, after 0.08651s
[info] Sorting edges by renumbered start ... ok, after 0.011522s
[info] Writing used edges ... ok, after 0.036492s -- Processed 430114 edges
[info] Writing way meta-data ... ok, after 0.002909s -- Metadata contains << 114321 entries.
[info] Collecting node information on 0 maneuver overrides...ok, after 0s
[info] Collecting node information on 1325 restrictions...ok, after 0.001102s
[info] writing street name index ... ok, after 0.005342s
[info] extraction finished after 6.54948s
[info] Generating edge-expanded graph representation
[info] . 10% . 20% . 30% . 40% . 50% . 60% . 70% . 80% . 90% . 100%
[info] Node compression ratio: 0.392367
[info] Edge compression ratio: 0.434504
[info] graph compression removed 99984 annotations of 114321 in 0.07511 seconds
[info] Find segregated edges in node-based graph ...
[info] ok, after 0.471304s
[info] Segregated edges count = 5526
[info] Writing nodes for nodes-based and edges-based graphs ...
[info] Geometry successfully removed:
compressed edges: 371500
compressed geometries: 868718
longest chain length: 75
cmpr ratio: 0.427642
avg chain length: 2.33841
[info] Removing invalid restrictions...removed 27 invalid restrictions, after 0.000209s
[info] Constructing restriction graph on 1251 restrictions...ok, after 0.000219s
[info] Generating edge expanded nodes ...
[info] . 10% . 20% . 30% . 40% . 50% . 60% . 70% . 80% . 90% . 100%
[info] Expanding via-way turn restrictions ...
[info] . 10% . 20% . 30% . 40% . 50% . 60% . 70% . 80% . 90% . 100%
[info] Generated 347725 nodes (76 of which are duplicates) and 427497 segments in edge-expanded graph
[info] Generating edge-expanded edges
[info] . 10% . 20% . 30% . 40% . 50% . 60% . 70% . 80% . 90% .
[info] Sorting and writing 0 maneuver overrides...
[info] done.
[info] Renumbering turns
[info] Writing 0 conditional turn penalties...
[info] Generated 427497 edge based node segments
[info] Node-based graph contains 342819 edges
[info] Edge-expanded graph ...
[info] contains 630238 edges
[info] Timing statistics for edge-expanded graph:
[info] Renumbering edges: 0.006096s
[info] Generating nodes: 0.074307s
[info] Generating edges: 0.686979s
[info] Generating guidance turns
[info] . 10% . 20% . 30% . 40% . 50% . 60% . 70% . 80% . 90% .
[info] done.
[info] Created 46 entry classes and 2697 Bearing Classes
[info] Handled: 3015 of 6455 lanes: 46.708 %.
[info] Assigned 796975 turn instruction types:
[info] new name: 13512 (1.70%)
[info] continue: 57764 (7.25%)
[info] turn: 293171 (36.79%)
[info] merge: 89 (0.01%)
[info] on ramp: 222 (0.03%)
[info] off ramp: 97 (0.01%)
[info] fork: 1683 (0.21%)
[info] end of road: 133389 (16.74%)
[info] notification: 16 (0.00%)
[info] enter roundabout: 80 (0.01%)
[info] enter and exit roundabout: 3 (0.00%)
[info] enter rotary: 62 (0.01%)
[info] enter and exit rotary: 7 (0.00%)
[info] enter roundabout turn: 24 (0.00%)
[info] (noturn): 123830 (15.54%)
[info] (suppressed): 172457 (21.64%)
[info] roundabout: 3 (0.00%)
[info] exit roundabout: 87 (0.01%)
[info] rotary: 7 (0.00%)
[info] exit rotary: 78 (0.01%)
[info] exit roundabout turn: 24 (0.00%)
[info] (stay on roundabout): 163 (0.02%)
[info] (sliproad): 207 (0.03%)
[info] Assigned 796975 turn instruction modifiers:
[info] uturn: 48529 (6.09%)
[info] sharp right: 5306 (0.67%)
[info] right: 219122 (27.49%)
[info] slight right: 10401 (1.31%)
[info] straight: 286911 (36.00%)
[info] slight left: 10365 (1.30%)
[info] left: 210499 (26.41%)
[info] sharp left: 5842 (0.73%)
[info] Guidance turn annotations took 1.15134s
[info] Writing Intersection Classification Data
[info] ok, after 0.010836s
[info] Writing Turns and Lane Data...
[info] ok, after 0.021483s
[info] Saving edge-based node weights to file.
[info] Done writing. (0.014786)
[info] Computing strictly connected components ...
[info] Found 1960 SCC (1 large, 1959 small)
[info] SCC run took: 0.016056s
[info] Building r-tree ...
[info] Constructing r-tree of 427497 segments build on-top of 397852 coordinates
[info] finished r-tree construction in 0.737508 seconds
[info] Writing edge-based-graph edges ...
[info] ok, after 3.54448s
[info] Processed 630238 edges
[info] Expansion: 85005 nodes/sec and 74295 edges/sec
[info] To prepare the data for routing, run: ./osrm-contract "/data/berlin-latest.osrm"
[info] RAM: peak bytes used: 463327232

Could you explain why this is happening ? Do I need to download and pre-process every sub-region separetely ?

Kind regards,
Simon

@Fergoth
Copy link

Fergoth commented Feb 9, 2023

Could you explain why this is happening
@simon-vanherck
I had the same problem. You need more memory for osrm-extract
Mine 3.3 gb pbf eat around 12 gb on excracting.
изображение
This setting was enough for me

@osvaldojrp
Copy link

Just a tip for those working with very extensive regions. In my case I was trying to work with the whole Brazil. I couldn’t extract the most recent osm.pbf file, but I just needed something up to 2020. The 2020 file is half the size of the 2023 one, so I was able to complete the process.

@JDittmerCOM
Copy link

Is there a way to write your own isochrone with it?
I already tried to make one with GPT, Claude.ai and Bard, but everything didn't work because the url doesn't work.
The AIs use either isochrone or table in the URL, but both don't work.
Does anyone of you have a solution to this? Is that even possible?

@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