0
votes

A locally running Azure Functions app is available from http://localhost:7071. The server side rendered react app is exposed at http://localhost:7070. Both the functions app and the react app are reverse proxied from a simple nginx container locally hosted (http://localhost:7072). For the sake of completeness, here's the nginx conf:

http {
    server {    
        listen 80 default_server;
        listen [::]:80 default_server;
        server_name  mywebapp-localdev;

        location /api {  
            proxy_pass http://10.0.75.1:7071;  
        }
        location / {  
            proxy_pass http://10.0.75.1:7070;  
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
    }
}

Here's the issue: if the address http://10.0.75.1:7071/api/hello-world is hit directly from the browser, the function behaves as expected. However if the function is called through the reverse proxy (http://localhost:7072/api/hello-world) then it times out. A couple tests from within the nginx container also indicate that the port 7071 on 10.0.75.1 is unreachable.

The question is: how is it possible to access a locally running Azure Function (using func host start) from a Docker container also running locally?

1
Could you go into a bit more detail on your architecture? Which parts are running in Docker containers and which aren't? For one container to access the ports in another container, once option would be to launch both containers in the same Docker network. Not sure if that's what you're looking for here.Katy Shimizu
The idea is to have both the web app and the function running locally and only the nginx running in a container since the development machine is Windows (cosmos and azure storage emulator are required) so the nginx reverse proxy is used to hide both dev instances. Unfortunately the container can't access the azure function server running locally at the ip address mentioned in my question.Étienne Brouillard
The ip 10.0.75.1 is from what I understand a bridge between the host and the containers thus explaining my attempt above.Étienne Brouillard

1 Answers

1
votes

Got it:

Instead of using the IP address mentioned above, all is necessary is to use an internal host resolving address (host.docker.internal) instead:

{
    location / {  
        proxy_pass http://host.docker.internal:7070;  
    }
}

I stumbled upon many different answers depending on the version of Docker. This fixed it.