Skip to content

ADDING COMPOSE #7208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions README2.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Docker Compose Setup for Project OSRM

This directory contains a **Docker Compose configuration** to simplify running [Project OSRM](https://github.com/Project-OSRM/osrm-backend).

With this way:

* Only use docker compose up -d  
* It launches a **frontend service** with health checks.
* Don't need to ensure services start in the correct order.

---

## Directory Structure

```
osrm-backend/
├── docker-compose.yml
├── prepare_osrm.sh
```

---

## Quick Start

### Clone this repository

```bash
git clone https://github.com/elshan2000/osrm-backend.git
cd osrm-backend
```

###


## How It Works

### Init Service

* Checks for the marker file `osrm_is_created`.
* If not present, runs:

* `osrm-extract`
* `osrm-partition`
* `osrm-customize`
* Creates the marker file.
* Exits after preparation.

### Backend Service

* Depends on the **frontend healthcheck**.
* Starts `osrm-routed` serving prepared data.

### Frontend Service

* Periodically checks for the presence of the marker file `osrm_is_created`.
* Reports `healthy` when the preparation is complete.
* This readiness allows the backend service to start safely.

---

## Health Check Logic

The **frontend** container performs a health check by verifying:

```
/data/osrm_is_created
```

Once the file exists, the health check reports `healthy`. This ensures that:

Data preparation is complete before routing starts.

---

## Clean Up

To stop and remove all containers:

```bash
docker compose down
```

To force re-preparation of the data (for example, if you want to regenerate `.osrm` files):

```bash
docker compose down
rm ./data/osrm_is_created
docker compose up -d
```

---

## Contribution

This Docker Compose configuration was contributed by [elshan2000](https://github.com/elshan2000).

Feel free to open issues or submit improvements!

---

## License

This project follows the [Project OSRM](https://github.com/Project-OSRM/osrm-backend) license (BSD-2-Clause).
66 changes: 66 additions & 0 deletions docker_comopse/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
services:
osrm-extract_partition_customize:
image: ghcr.io/project-osrm/osrm-backend:v6.0.0
volumes:
- /mnt/graid/projects/osrm:/data
- ./prepare_osrm.sh:/prepare_osrm.sh
command: /prepare_osrm.sh

restart: "no"
networks:
- osrm_osrm-network


osrm-routed:
hostname: osrm-routed
image: ghcr.io/project-osrm/osrm-backend:v6.0.0
ports:
#- "5050:5000"
volumes:
- /mnt/graid/projects/osrm:/data
command: >
osrm-routed
--algorithm mld
--max-matching-size 100
--max-trip-size 100
--max-table-size 100
--max-nearest-size 100
--max-alternatives 3
--ip 0.0.0.0
--port 5000
/data/iran-latest.osrm
networks:
- nginx-network
- osrm_osrm-network
restart: always

depends_on:
osrm-frontend:
condition: service_healthy

osrm-frontend:
hostname: osrm-frontend
image: osrm/osrm-frontend
#ports:
# - "9966:9966"
restart: always
environment:
# - OSRM_BACKEND_URL=https://osrmapi.buluttakin.com:443
- OSRM_BACKEND_URL=osrm-routed:5000
networks:
- nginx-network
- osrm_osrm-network
volumes:
- /mnt/graid/projects/osrm:/data
healthcheck:
test: ["CMD", "test", "-f", "/data/osrm_map_generated"]
interval: 6s
timeout: 600s
retries: 60000


networks:
nginx-network:
external: true
osrm_osrm-network:
driver: bridge
12 changes: 12 additions & 0 deletions docker_comopse/prepare_osrm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

if [ -f /data/osrm_map_generated ]; then
echo "OSRM data already prepared, skipping."
else
echo "OSRM data not found, preparing..."
osrm-extract -p /opt/car.lua /data/iran-latest.osm.pbf &&
osrm-partition /data/iran-latest.osrm &&
osrm-customize /data/iran-latest.osrm &&
touch /data/osrm_map_generated
fi