使用wget访问本地服务器时读取错误



我有一个节点应用程序运行在端口5000(从docker容器),但我无法访问它。

我尝试运行wget http://localhost:5000后炮击到服务器,但我得到以下错误:

--2021-09-09 18:44:44--  http://localhost:5000/
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:5000... connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.
Retrying.
--2021-09-09 18:45:17--  (try: 2)  http://localhost:5000/
Connecting to localhost (localhost)|::1|:5000... connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.
Retrying.```
When I run the container on my local computer, I have no trouble accessing it this way, so I'm guessing it's something on the server, but I don't know where to look next.

EDITS
Output of `sudo netstat -anp --tcp | grep 5000 | grep LISTEN`

tcp        0      0 0.0.0.0:5000            0.0.0.0:*               LISTEN      16480/docker-proxy
tcp6       0      0 :::5000                 :::*                    LISTEN      16486/docker-proxy

在服务器上,检查端口5000上是否有侦听

netstat -anp --tcp | grep 5000 | grep LISTEN

它应该告诉你有东西正在监听127.0.0.1:50000.0.0.0:5000。前者是一个环回地址(只能在服务器内部访问),后者是服务器上具有IP的任何接口(因此如果本地防火墙允许,它可以在服务器外部访问)。

如果5000上没有监听,那么很可能docker容器没有公开端口。

  • 你可以把EXPOSE 5000放在你的Dockerfile.
  • 你可以把--expose 5000添加到你的docker run命令
  • 你可以把-p 5000:5000添加到你的docker run命令

如果您在本地计算机上运行端口5000时可以访问它,则可能是因为您添加了一个环境变量来自动公开端口。

最新更新