VROOM-Project / vroom-docker

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

SOLVED: "Error code 3: Failed to connect to 0.0.0.0:5000" #35

Closed AndreRoss92 closed 3 years ago

AndreRoss92 commented 3 years ago

Hi, I am quite new to docker and setting up local servers.

I have followed all the instructions for setting up OSRM and VROOM, but when running a pyhton script querying VROOM I get this response

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

The query works if launched for the demo server, and OSRM is running correctly on port 5000

Any idea on where the problem might be?

Thank you :)

nilsnolde commented 3 years ago

Can you share how you setup the OSRM and vroom instances? If it's all in one docker-compose, see this comment (and also the README points that out): https://github.com/VROOM-Project/vroom-docker/issues/27#issuecomment-816896590

AndreRoss92 commented 3 years ago

Hi, I set them up separrately by running the following commands

docker run -t -i -p 5000:5000 -v "${PWD}:/data" osrm/osrm-backend osrm-routed --algorithm mld /data/italy-latest.osrm

docker run -dt --name vroom -p 3000:3000 -v $PWD/conf:/conf -e VROOM_ROUTER=osrm vroomvrp/vroom-docker:v1.9.0

nilsnolde commented 3 years ago

ok, then it's more appropriate in the docker repo.

In your case: if you run vroom as described in the README, it'll do what you expect: https://github.com/VROOM-Project/vroom-docker#vroom-docker-image

hint: --net host is important.

AndreRoss92 commented 3 years ago

Thank you @nilsnolde ,

I had already tried with --net host, and running the same python script gives me the following error instead

image

nilsnolde commented 3 years ago

if you do curl --fail http://localhost:3000/health on the host machine? Probably works with localhost instead of local IP ;) not kidding.. not much of a networking guy, but I've had issues like that before, seems a lot of libs/apps treat the 2 subtly different.

nilsnolde commented 3 years ago

Oh seems you're on Windows.. Just visit http://localhost:3000/health in your browser then. If you get simple blank page without an error it can talk to vroom.

AndreRoss92 commented 3 years ago

both with curl and visiting http://localhost:3000/healt is failing

image

nilsnolde commented 3 years ago

hm, then it needs to be some windows specific problem.. both

docker run -dt --name vroom -p 3000:3000 -v $PWD/conf:/conf -e VROOM_ROUTER=osrm vroomvrp/vroom-docker:v1.9.0 docker run -dt --name vroom --net host -v $PWD/conf:/conf -e VROOM_ROUTER=osrm vroomvrp/vroom-docker:v1.9.0

are working for me on linux. I can quickly check next time I'm on Win.

AndreRoss92 commented 3 years ago

Thanks @nilsnolde

I made a couple of test and the results are the following

With docker run -dt --name vroom -p 3000:3000 -v $PWD/conf:/conf -e VROOM_ROUTER=osrm vroomvrp/vroom-docker:v1.9.0 -> I can access localhost:3000 successfully, but I get the "failed to connect to 0.0.0.0:5000" in Python

With docker run -dt --name vroom --net host -v $PWD/conf:/conf -e VROOM_ROUTER=osrm vroomvrp/vroom-docker:v1.9.0 -> localhost:3000 doesn't work at all

AndreRoss92 commented 3 years ago

I have solved the issue by using the attached docker-compose...thank you for your help

version: "2.4" services: vroom: image: vroomvrp/vroom-docker:v1.8.0 container_name: vroom volumes:

networks: static-network: ipam: config:

constantineh commented 3 years ago

@AndreRoss92 I'm having the same issue! Can't figure how to use docker-compose.yml, can you please explain? I have copied it into config.yml and restart docker but nothing, still getting {"code":3,"error":"Failed to connect to 0.0.0.0:5000"} I guess it's not working like this. OSRM docker image is working fine through localhost:5000 Any help will be welcome. Thank you

nilsnolde commented 3 years ago

Can you copy your config.yml and docker-compose.yml @constantineh ? And how are you running OSRM?

constantineh commented 3 years ago

Hi @nilsnolde, I tried to use the following docker-compose.yml (same as provided to get started with my country data for osrm) but I'm getting an error regarding the "host". Any suggestions to fix the issue? I will also try to modify and use the docker-compose provided above by @AndreRoss92.

See complete command line response below:

Docker Compose is now in the Docker CLI, try `docker compose up`

Creating network "vroom_default" with the default driver
Pulling osrm (osrm/osrm-backend:)...
latest: Pulling from osrm/osrm-backend
fa1690ae9228: Pulling fs layer
fa1690ae9228: Downloading [>                                                  ]  232.6kB/22.53MBwnload complete
3abf697e1aa1: Waiting
fa1690ae9228: Downloading [==>                                                ]   1.15MB/22.53MBwnloading [==>                                                ] fa1690ae9228: Downloading [====>                                              ]  2.091MB/22.53MBwnloading [======>                                            ] fa1690ae9228: Downloading [=======>                                           ] fa1690ae9228: Pull complete
d62d4c1e7f80: Pull complete
9499fb15748f: Pull complete
3abf697e1aa1: Pull complete
d1782613be5e: Pull complete
Digest: sha256:7c72114f7744ccc94c3fe208663197104e44d105ba66dcb99e40b28fc56e40f9
Status: Downloaded newer image for osrm/osrm-backend:latest
Pulling vroom (vroomvrp/vroom-docker:v1.10.0)...
v1.10.0: Pulling from vroomvrp/vroom-docker
f7ec5a41d630: Pull complete
af85e22911d9: Pull complete
07060573ed70: Pull complete
a082ae6404c8: Pull complete
0aa4da5b6a9b: Pull complete
e6800109a6e6: Pull complete
17b951da241f: Pull complete
126790e7b93b: Pull complete
3a78032756fb: Pull complete
Digest: sha256:c2971c02a5c2f2e4b1c8507bde40db4a0f305c1a2fefaec8a0db02e76e01a53b
Status: Downloaded newer image for vroomvrp/vroom-docker:v1.10.0
Creating osrm ... done
Creating host ... 

ERROR: for host  "host" network_mode is incompatible with port_bindings

ERROR: for vroom  "host" network_mode is incompatible with port_bindings
Traceback (most recent call last):
  File "docker-compose", line 3, in <module>
  File "compose/cli/main.py", line 81, in main
  File "compose/cli/main.py", line 203, in perform_command
  File "compose/metrics/decorator.py", line 18, in wrapper
  File "compose/cli/main.py", line 1189, in up
  File "compose/cli/main.py", line 1169, in up
  File "compose/project.py", line 697, in up
  File "compose/parallel.py", line 108, in parallel_execute
  File "compose/parallel.py", line 206, in producer
  File "compose/project.py", line 679, in do
  File "compose/service.py", line 559, in execute_convergence_plan
  File "compose/service.py", line 473, in _execute_convergence_create
  File "compose/parallel.py", line 108, in parallel_execute
  File "compose/parallel.py", line 206, in producer
  File "compose/service.py", line 478, in <lambda>
  File "compose/service.py", line 457, in create_and_start
  File "compose/service.py", line 330, in create_container
  File "compose/service.py", line 939, in _get_container_create_options
  File "compose/service.py", line 1014, in _get_container_host_config
  File "docker/api/container.py", line 598, in create_host_config
  File "docker/types/containers.py", line 338, in __init__
docker.errors.InvalidArgument: "host" network_mode is incompatible with port_bindings
[42992] Failed to execute script docker-compose

Also here is the docker-compose.yml:

version: "2.4"
services:
  vroom:
    network_mode: host
    image: vroomvrp/vroom-docker:v1.10.0
    container_name: host
    ports:
      - 3000:3000
    volumes:
      - ./vroom-conf/:/conf
    environment:
      - VROOM_ROUTER=osrm # router to use, osrm, valhalla or ors
    depends_on:
      - osrm

  # EXAMPLE for OSRM, please consult the repo for details: https://hub.docker.com/r/osrm/osrm-backend/
  osrm:
    image: osrm/osrm-backend
    container_name: osrm
    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/cyprus-latest.osrm"
nilsnolde commented 3 years ago

ERROR: for host "host" network_mode is incompatible with port_bindings

can't express it better tbh. either or, can't use both.

Docker Compose is now in the Docker CLI, try docker compose up interesting, didn't know it was integrated now!

constantineh commented 3 years ago

@nilsnolde can you explain a bit more what you mean "either or, can't use both" ? I'm quite new at docker and trying to figure it out... Thank you

nilsnolde commented 3 years ago
    container_name: host
    ports:
      - 5000:5000

they can't go together.

e.g. https://forums.docker.com/t/docker-errors-invalidargument-host-network-mode-is-incompatible-with-port-bindings/103492 or lots of other forums articles when you google that error message.

constantineh commented 3 years ago

@nilsnolde finally I was able to fix the issue using the latest docker-compose.yml Not sure why I had in vroom service container_name: host and also port: -3000:3000 😏

Here is my docker-compose.yml

version: "2.4"
services:
  vroom:
    network_mode: host
    image: vroomvrp/vroom-docker:v1.10.0
    container_name: vroom
    volumes:
      - ./vroom-conf/:/conf
    environment:
      - VROOM_ROUTER=osrm # router to use, osrm, valhalla or ors
    depends_on:
      - osrm

  # EXAMPLE for OSRM, please consult the repo for details: https://hub.docker.com/r/osrm/osrm-backend/
  osrm:
    image: osrm/osrm-backend
    container_name: osrm
    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/cyprus-latest.osrm"

OSRM works fine if I call for example: curl "http://localhost:5000/route/v1/driving/33.375698,35.155582;33.375698,35.152795?steps=true"

However, if I run vroom, for example:

curl --header "Content-Type:application/json" --data '{  "vehicles": [
    {
      "id": 1,
      "start": [33.33480,35.07207],
      "end": [33.33480,35.07207],
      "capacity": [14],
      "skills": [0],
      "time_window": [0, 28800]
    }
  ],
  "shipments": [
    {
      "amount": [1],
      "skills": [0],
      "pickup": {
        "id": 2,
        "service": 90,
        "location": [33.32342,35.07401]
      },
      "delivery": {
        "id": 3,
        "service": 90,
        "location": [33.32795,35.08159]
      }
    }
  ],"options":{"g":true}}' http://localhost:3000/

I have as a response: curl: (7) Failed to connect to localhost port 3000: Connection refused

Also, if I leave in vroom service ports: - 3000:3000 and run docker-compose I get as a response:

Creating network "docker_default" with the default driver
Creating osrm ... done
Creating vroom ... 

ERROR: for vroom  "host" network_mode is incompatible with port_bindings

ERROR: for vroom  "host" network_mode is incompatible with port_bindings
Traceback (most recent call last):
  File "docker-compose", line 3, in <module>
  File "compose/cli/main.py", line 81, in main
  File "compose/cli/main.py", line 203, in perform_command
  File "compose/metrics/decorator.py", line 18, in wrapper
  File "compose/cli/main.py", line 1189, in up
  File "compose/cli/main.py", line 1169, in up
  File "compose/project.py", line 697, in up
  File "compose/parallel.py", line 108, in parallel_execute
  File "compose/parallel.py", line 206, in producer
  File "compose/project.py", line 679, in do
  File "compose/service.py", line 559, in execute_convergence_plan
  File "compose/service.py", line 473, in _execute_convergence_create
  File "compose/parallel.py", line 108, in parallel_execute
  File "compose/parallel.py", line 206, in producer
  File "compose/service.py", line 478, in <lambda>
  File "compose/service.py", line 457, in create_and_start
  File "compose/service.py", line 330, in create_container
  File "compose/service.py", line 939, in _get_container_create_options
  File "compose/service.py", line 1014, in _get_container_host_config
  File "docker/api/container.py", line 598, in create_host_config
  File "docker/types/containers.py", line 338, in __init__
docker.errors.InvalidArgument: "host" network_mode is incompatible with port_bindings
[46760] Failed to execute script docker-compose

I believe I miss something on my config.yml below:

cliArgs:
  geometry: false # retrieve geometry (-g)
  planmode: false # run vroom in plan mode (-c) if set to true
  threads: 4 # number of threads to use (-t)
  explore: 5 # exploration level to use (0..5) (-x)
  limit: '1mb' # max request size
  logdir: '/..' # the path for the logs relative to ./src
  logsize: '100M' # max log file size for rotation
  maxlocations: 1000 # max number of jobs/shipments locations
  maxvehicles: 200 # max number of vehicles
  override: true # allow cli options override (-c, -g, -t and -x)
  path: '' # VROOM path (if not in $PATH)
  port: 3000 # expressjs port
  router: 'osrm' # routing backend (osrm, libosrm or ors)
  timeout: 300000 # milli-seconds
  baseurl: '/' #base url for api
routingServers:
  osrm:
    car:
      host: '0.0.0.0'
      port: '5000'
    bike:
      host: '0.0.0.0'
      port: '5000'
    foot:
      host: '0.0.0.0'
      port: '5000'
  ors:
    driving-car:
      host: '0.0.0.0'
      port: '8080'
    driving-hgv:
      host: '0.0.0.0'
      port: '8080'
    cycling-regular:
      host: '0.0.0.0'
      port: '8080'
    cycling-mountain:
      host: '0.0.0.0'
      port: '8080'
    cycling-road:
      host: '0.0.0.0'
      port: '8080'
    cycling-electric:
      host: '0.0.0.0'
      port: '8080'
    foot-walking:
      host: '0.0.0.0'
      port: '8080'
    foot-hiking:
      host: '0.0.0.0'
      port: '8080'
  valhalla:
    auto:
      host: '0.0.0.0'
      port: '8002'
    bicycle:
      host: '0.0.0.0'
      port: '8002'
    pedestrian:
      host: '0.0.0.0'
      port: '8002'
    motorcycle:
      host: '0.0.0.0'
      port: '8002'
    motor_scooter:
      host: '0.0.0.0'
      port: '8002'
    taxi:
      host: '0.0.0.0'
      port: '8002'
    hov:
      host: '0.0.0.0'
      port: '8002'
    truck:
      host: '0.0.0.0'
      port: '8002'
    bus:
      host: '0.0.0.0'
      port: '8002'

Any ideas?

constantineh commented 3 years ago

Here is also what I get with docker ps

CONTAINER ID   IMAGE                           COMMAND                  CREATED          STATUS                    PORTS                                       NAMES
8fc57fe2957c   vroomvrp/vroom-docker:v1.10.0   "/bin/bash /docker-e…"   50 seconds ago   Up 50 seconds (healthy)                                               vroom
2bc7d4008df9   osrm/osrm-backend               "osrm-routed --max-m…"   54 seconds ago   Up 50 seconds             0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   osrm
nilsnolde commented 3 years ago

Hm.. the docker-compose.yml looks fine, also the docker ps. You shouldn't need to change anything the vroom config, that's the advantage of network_mode: host. Can you try to:

What that'll do is set up a private docker network where vroom calls osrm within this private network, that's why you have to set the host to the docker-compose's service name for OSRM. That's really the better way to go anyways, but requires some manual stuff. If that works for you, then I need to investigate at some point why network_mode: host doesn't..

constantineh commented 3 years ago

Finally works like a charm with the above setup! I was reading in stack overflow that it might be a problem using network_mode: host with macs. Check it here: https://stackoverflow.com/questions/46286741/is-there-a-workaround-to-use-the-hosts-network-in-docker-for-mac

gisops-bot commented 3 years ago

Ah cool thanks! That should make it into the readme actually