无法从 Docker 容器访问本地运行的 Azure Functions

标签 azure docker nginx azure-functions

本地运行的 Azure Functions 应用程序可从 http://localhost:7071 获取。 。 服务器端渲染的 React 应用程序公开于 http://localhost:7070 。 函数应用程序和 React 应用程序都是从本地托管的简单 nginx 容器 ( http://localhost:7072 ) 进行反向代理。为了完整起见,这是 nginx 配置:

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;
        }
    }
}

问题是:如果地址 http://10.0.75.1:7071/api/hello-world直接从浏览器点击,该函数的行为符合预期。但是,如果通过反向代理( http://localhost:7072/api/hello-world )调用该函数,则会超时。 nginx 容器内的一些测试还表明 10.0.75.1 上的端口 7071 无法访问。

问题是:如何从也在本地运行的 Docker 容器访问本地运行的 Azure Function(使用 func host start)?

最佳答案

明白了:

不使用上述 IP 地址,只需使用内部主机解析地址 (host.docker.internal) 即可:

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

根据 Docker 的版本,我偶然发现了许多不同的答案。这解决了它。

关于无法从 Docker 容器访问本地运行的 Azure Functions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54428750/

相关文章:

docker - Mercure Docker 由于忽略 docker-compose 中的 JWT_KEY 而导致 JWT 签名无效

postgresql - docker compose : postgresql create db, 用户通过并授予权限

node.js - Meteor NGinx 网关错误

azure - 打开AI完成回复LENGTH

用于列出代理池和运行的作业的 Azure CLI 命令

docker - 当 `docker exec`命令在已经运行的容器上运行时,是否可以设置默认命令?

php - nginx X-Frame-Options 仍然具有相同的值

nginx - 如何使用查询字符串生成带有子域的 URL 到新 URL?

.net - 在计算模拟器中的 IIS Express 下运行的 Web 角色的 HTTP 500

azure - Sitecore Solr 负载均衡