apache / openwhisk-apigateway

Apache OpenWhisk API Gateway service for exposing actions as REST interfaces.
https://openwhisk.apache.org/
Apache License 2.0
64 stars 45 forks source link

container cannot resolve http://host.docker.internal #345

Closed rabbah closed 4 years ago

rabbah commented 5 years ago

When using the standalone controller, the api gateaway must relay requests to http://host.docker.internal:3233.

2019/06/26 23:44:30 [error] 35#0: *206 host.docker.internal could not be resolved 
(3: Host not found), client: 172.17.0.1, server: , 
request: "GET /api/23bc46b1-71f6-4ed5-8c54-816aa4f8c502/api/greeting HTTP/1.1", 
host: "172.17.0.1:9001"
2019/06/26 23:44:30 [info] 35#0: *206 client 172.17.0.1 closed keepalive connection

cc @jthomas @chetanmeh

Note that curling http://host.docker.internal:3233/api/v1/web/guest/default/my_service-dev-hello from inside the api gateway container responds as expected.

rabbah commented 5 years ago
> docker run --rm openwhisk/apigateway nslookup host.docker.internal
nslookup: can't resolve '(null)': Name does not resolve

Name:      host.docker.internal
Address 1: 192.168.65.2
> docker run --rm openwhisk/apigateway ping host.docker.internal
PING host.docker.internal (192.168.65.2): 56 data bytes
64 bytes from 192.168.65.2: seq=0 ttl=37 time=0.293 ms
mhamann commented 5 years ago

@rabbah are you running this on a user-defined network via docker run --network <foo>?

rabbah commented 5 years ago

Thanks @mhamann - not explicitly (the commands for docker run above don't specify a network, namely). I am using docker on mac.

dgrove-oss commented 5 years ago

Might have the same root cause as https://github.com/apache/incubator-openwhisk-deploy-kube/issues/436 ?

rabbah commented 5 years ago

Per @ddragosd's suggestion I checked the resolver.conf content.

bash-4.4# cat  "/etc/api-gateway/conf.d/includes/resolvers.conf"
resolver 192.168.65.1;

bash-4.4# cat /etc/resolv.conf 
# This file is included on the metadata iso
nameserver 192.168.65.1
domain home
nslookup host.docker.internal 192.168.65.1
Server:    192.168.65.1
Address 1: 192.168.65.1

Name:      host.docker.internal
Address 1: 192.168.65.2
bash-4.4# curl 192.168.65.2:3233/api/v1
{"api_info":{"build":"2019-06-29T09:38:55-0400","...
ddragosd commented 5 years ago

@rabbah how can I simulate your local setup so I can debug more ? Do I just simply docker run the OW GW ?

rabbah commented 5 years ago

i'll verify but i believe my steps were: wskdev apigw -e"whisk_api_host_name=host.docker.internal" and then i uses the sls cli but it failed with the issue above but i found that wsk actually worked (i do not recall if i had to do anything special for wsk).

mhamann commented 5 years ago

@rabbah given the mailing list notes I've seen, do we consider this resolved?

rabbah commented 5 years ago

We didn't get to the root cause of why the host name cannot be resolved inside the container. @chetanmeh implemented a workaround to get by. If one one is going to actively pursue this, or have insights into what's going on, might as well close.

mhamann commented 4 years ago

I ran into this issue on another alpine-based w/ nginx container I was working with. Came across this answer on StackOverflow, which fixed it for me: https://stackoverflow.com/questions/35471967/nginx-doesnt-get-host-from-embedded-dns-in-docker-1-10-1

Essentially, nginx is attempting to resolve an IPv6 address for the hostname, which isn't going to work in most cases. Disabling ipv6 resolves the problem. If IPv6 becomes more prolific, then we may need to revisit this down the road, but likely other things will have changed by that time, which will make the resolution path much less onerous.

PR has been opened.