VROOM-Project / vroom-docker

Docker image for vroom and vroom-express
BSD 2-Clause "Simplified" License
88 stars 58 forks source link

Add OSRM to docker-compose.yml #5

Closed nilsnolde closed 4 years ago

nilsnolde commented 4 years ago

ORS was easy for me. I'd appreciate if someone with OSRM experience (I never even set it up myself) could provide the example for OSRM.

jcoupey commented 4 years ago

Just to make sure I get this right, the purpose is to pull a pre-existing OSRM image independently? And this is the main difference from the work of @iedmrc at https://github.com/iedmrc/vroom-docker?

nilsnolde commented 4 years ago

Exactly. OSRM already has its Dockerfile. Including it via docker-compose makes more sense IMHO, since you can swap with ORS (or Valhalla in close future) easily and the vroom image doesn't become dependent on OSRM.

Actually the integration seems to be easy, as it only requires to map a directory holding the PBF, OSRM Docker integration is a little poor, one can't even configure the port it should run on it seems. Maybe @iedmrc has a bit more experience with running it in Docker, but from what I see I can include it myself. Straight forward. Should've taken the 2 minutes it takes to read through the Docker readme;)

mhosman commented 4 years ago

You can attach something like this to the docker-compose.yml (with the vroom container data).

    osrm:
        container_name: osrm
        image: osrm/osrm-backend
        restart: always
        ports:
            - "5000:5000"
        volumes:
            - ./osrm:/data
        command: "osrm-routed --max-matching-size 1000 --max-table-size 1000 --max-viaroute-size 1000 --algorithm mld /data/map.osrm"

The only problem in my case is that I'm able to connect to both containers from outside, buy I don't know why VROOM container is not able to connect to port 5000 of the osrm container.

Error from VROOM Express:

{
    "code": 3,
    "error": "Failed to connect to 0.0.0.0:5000"
}
iedmrc commented 4 years ago

You can attach something like this to the docker-compose.yml (with the vroom container data).

    osrm:
        container_name: osrm
        image: osrm/osrm-backend
        restart: always
        ports:
            - "5000:5000"
        volumes:
            - ./osrm:/data
        command: "osrm-routed --max-matching-size 1000 --max-table-size 1000 --max-viaroute-size 1000 --algorithm mld /data/map.osrm"

The only problem in my case is that I'm able to connect to both containers from outside, buy I don't know why VROOM container is not able to connect to port 5000 of the osrm container.

Error from VROOM Express:

{
    "code": 3,
    "error": "Failed to connect to 0.0.0.0:5000"
}

It's because VROOM is looking for 5000 port localy but osrm is served in another container (think they are working o separate machines). So you need to create a network then configure vroom-express to connect osrm with its service name. e.g. osrm:5000

mhosman commented 4 years ago

Hey @iedmrc, thanks for your response. I've tried that but still fails. Do you have an example? Not able to connect at least from VROOM Express 0.5.0.

iedmrc commented 4 years ago

Could you please check the link here:

https://github.com/iedmrc/awesome-docker-compose/blob/master/vroom/docker-compose.yml

mhosman commented 4 years ago

Yes @iedmrc, I already checked that. But still not working (is working only with old VROOM Express versions). Maybe because of new config.yml file? I changed the configuration inside the container but I don't know why is still trying to reach 0.0.0.0:5000.

iedmrc commented 4 years ago

If you use the same image provided in that docker-compose.yml file, then it's already defined like so: https://github.com/iedmrc/vroom-docker/blob/master/config.js#L36 That means, it should try to connect osrm:5000 (not 0.0.0.0:5000)

mhosman commented 4 years ago

@iedmrc, I created a new one because your repository is not running the latest vroom-express version and some things changed. Maybe something is wrong when I create the image, but I can't find the problem.

mhosman commented 4 years ago

The issue is solved. The problem was with the config.yml. Thank you @iedmrc

This is the docker-compose.yml

version: "3"
services:
    osrm:
        container_name: osrm
        image: osrm/osrm-backend
        restart: always
        ports:
            - "5000:5000"
        volumes:
            - ./osrm:/data
        networks:
            tsp_network:
                aliases:
                - osrm
        command: "osrm-routed --max-matching-size 1000 --max-table-size 1000 --max-viaroute-size 1000 --algorithm mld /data/map.osrm"
    vroom:
        image: vroomproject/vroom-docker:v1.6.0
        container_name: vroom
        restart: always
        ports:
            - "3000:3000"
        volumes:
            - ./vroom_conf/:/conf
        networks:
            tsp_network:
                aliases:
                - vroom
        depends_on:
            - osrm

networks:
    tsp_network:
        driver: bridge
nilsnolde commented 4 years ago

Actually that's covered fairly extensively in the README ;) https://github.com/VROOM-Project/vroom-docker#routing-server

Easiest is to set network_mode: host, then you don't have to alter the config file at all. As long as you don't need ports 5000 & 3000 for anything else.

iedmrc commented 4 years ago

Thanks @nilsnolde for the info but I think that is not the best practice. You should only bind the ports you need to expose to the public. And isolating the stack in a virtual private network is a big benefit of docker-compose stack.

nilsnolde commented 4 years ago

Absolutely agreed. For the ones who know what they're doing. Because they will also have to change the config.yml hosts to the service names.

I was generally rather going for the least resistance path, as I'm thinking a big chunk of the Docker audience are those who "quickly wanna give it a spin". Anyways, happy it worked in the end.

CHOMNANP commented 3 years ago

Actually that's covered fairly extensively in the README ;) https://github.com/VROOM-Project/vroom-docker#routing-server

Easiest is to set network_mode: host, then you don't have to alter the config file at all. As long as you don't need ports 5000 & 3000 for anything else.

This does not seem to work on Mac.