无法从浏览器访问Docker应用程序

matt_rule

我有一个.NET Core 2.1 API,当通过Windows中的Visual Studio运行时,它会从浏览器接收HTTP GET,并成功地从MySQL数据库返回数据。

我一直在尝试将API添加到Docker容器(在Ubuntu内)-可以构建,但是我无法从浏览器访问API:

火狐浏览器

我已经试过

  • 检查可用端口。这是相关的输出:

在此处输入图片说明

  • 使用其他浏览器进行连接:在Chromium中,它显示“无法访问此站点:本地主机意外关闭了连接。”
  • Testing unused ports in the browser to see if this returns a different message - for Firefox, unused ports return 'Unable to connect' instead of 'Secure connection Failed', and in Chromium they return 'localhost refused to connect.' instead of 'localhost unexpectedly closed the connection.'
  • In Firefox, configuring 'security.tls.insecure_fallback_hosts' to 'localhost'.
  • Double-checking that ports are mapped correctly in docker-compose.yml - under 'ports' for the relevant container, 44329 is mapped to 44329.
  • Running a DB query when the API starts and logging the result: this is successful. I run docker-compose up, the API starts, connects to the DB container, and it logs the result of an SQL query to a text file. So the problem is unlikely to be anything to do with the database.
  • Logging GET requests: Inside Windows, the GET requests are successfully logged, but in the Ubuntu Docker container, they're not.

This might be relevant: In Windows, the API only works properly if you start it from Visual Studio. If you execute dotnet webapi.dll, you get this output

...\netcoreapp2.1>dotnet webapi.dll
...
Now listening on: http://localhost:5000
Now listening on: https://localhost:5001
Application started. Press Ctrl+C to shut down.

So here it's not running on 44329; instead it's accessible via 5001 in the browser, where you get this message which is not chill at all: 在此处输入图片说明 Clicking 'ADVANCED' allows you to continue to the API.

  • So I've also tried connecting via 5001 in Ubuntu without luck.

Here's the output from 'docker-compose up':

matt@Matt-Ubuntu:~/docker2$ docker-compose up
Starting docker2_mysql_1 ... done
Starting docker2_dbmodelmapper_1 ... done
Attaching to docker2_mysql_1, docker2_dbmodelmapper_1
... (mysql stuff) ...
dbmodelmapper_1  | Hosting environment: Production
dbmodelmapper_1  | Content root path: /app
dbmodelmapper_1  | Now listening on: http://[::]:80
dbmodelmapper_1  | Application started. Press Ctrl+C to shut down.
  • Seeing the port 80, I've tried connecting to that, without success.

  • The relevant container as shown by docker ps is:

    在此处输入图片说明

What kind of issue am I looking at here?

matt_rule

正如多人在评论中指出的(感谢sp0gg,Martin Ullrich和Daniel Lerps),该API错误地侦听了端口80。

解决方案是将端口5000映射到docker-compose.yml中用于API容器的端口,并将其映射到API容器的Docker-compose.yml中,将端口5000映射到44329,同时在启动ASP.NET API时将Dockerfile传递为dotnet的参数:

ENTRYPOINT ["dotnet", "webapi.dll", "--urls", "http://*:5000;http://*:5001"]

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

无法从浏览器访问 Angular 应用程序容器

docker 应用程序构建但在运行浏览器后显示无法访问此站点

为什么我无法通过浏览器访问我的 docker 节点应用程序,在它工作的容器中?

在主机浏览器中访问在 docker 容器内运行的 Web 应用程序?

在Spring Boot应用程序中无法从浏览器访问http:inbound-gateway映射

无法从浏览器访问远程Spring Boot应用程序

Worklight应用程序访问移动浏览器cookie

运行 ASP.NET Core Web 应用程序的 Amazon Lightsail - 无法从浏览器访问网站

使用应用程序中嵌入的浏览器时,无法从Android上的网页访问地理位置

无法从浏览器访问 Docker tomcat

从单独的应用程序访问Web浏览器开发工具

访问Android应用程序上的浏览器历史记录

使用浏览器化的节点应用程序访问module.exports

通过Web浏览器界面上的多个用户访问的Qt应用程序

如何访问电子应用程序的当前浏览器窗口?

从浏览器访问在本地主机上运行的SignalR应用程序

从浏览器运行我的 VodaPay 小程序 web-view 应用程序时,我无法访问我的图书馆

闪亮的应用程序Docker容器未在浏览器中加载

ReactJS浏览器应用程序看不到Docker Compose网络中的内容

无法阻止浏览器页面在角度应用程序中刷新/重新加载

pdf在Ionic应用程序中的浏览器中但在移动设备中无法读取

SignalR在浏览器中无法在应用程序中工作

Angular应用程序无法在浏览器上正确呈现

Angular 应用程序无法加载到 Android 浏览器上

应用程序浏览器中的Andriod Facebook无法使用Facebook登录

Angular 5应用程序无法在iOS8中使用(浏览器堆栈)

谷歌浏览器无法在烧瓶应用程序中以硒开头

无法从另一个浏览器打开反应应用程序

angular4应用程序无法在智能电视的Web浏览器中运行(WebOSBrowser)