[英]Docker Container port access
I have created an image from an existing do.net application I can run locally.我已经从可以在本地运行的现有 do.net 应用程序创建了一个图像。
in my docker file I have EXPOSE 5000
在我的 docker 文件中,我有
EXPOSE 5000
In the docker compose: ports: [5000:5000]
在 docker 中撰写:
ports: [5000:5000]
I start the container using the command: docker run -d -p 5000:5000 --name my-reports my-reports:latest
我使用以下命令启动容器:
docker run -d -p 5000:5000 --name my-reports my-reports:latest
running the docker ps
command:运行
docker ps
命令:
NAMES
106c4929c0d6 my-reports:latest "dotnet my-reports" 8 minutes ago Up 8 minutes 0.0.0.0:5000->5000/tcp my-reports
The output of the entrypoint:入口点的output:
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: C:\app
netstat shows:网络统计显示:
C:\app>netstat -a
Active Connections
Proto Local Address Foreign Address State
TCP 0.0.0.0:135 106c4929c0d6:0 LISTENING
TCP 0.0.0.0:5985 106c4929c0d6:0 LISTENING
TCP 0.0.0.0:47001 106c4929c0d6:0 LISTENING
TCP 0.0.0.0:49152 106c4929c0d6:0 LISTENING
TCP 0.0.0.0:49153 106c4929c0d6:0 LISTENING
TCP 0.0.0.0:49154 106c4929c0d6:0 LISTENING
TCP 0.0.0.0:49155 106c4929c0d6:0 LISTENING
TCP 0.0.0.0:49160 106c4929c0d6:0 LISTENING
TCP 127.0.0.1:5000 106c4929c0d6:0 LISTENING
But I get timeouts trying to access the port from my machine via localhost:5000但是我尝试通过 localhost:5000 从我的机器访问端口时超时
You have already provided flag --name my-reports but your container is reporting the name as "vpi-harmony-reports".您已经提供了标志 --name my-reports 但您的容器将名称报告为“vpi-harmony-reports”。 Do kill the container and re-run the docker command.
一定要杀死容器并重新运行 docker 命令。 Also make sure you do not have firewall blocking 5000 port.
还要确保您没有防火墙阻止 5000 端口。
Your problem is that your app listens on localhost
.您的问题是您的应用程序在
localhost
上侦听。 This is only available inside the container.这仅在容器内可用。
You need to make your app listen on the public.network interface.您需要让您的应用在 public.network 接口上监听。 Most easy achieved by using
0.0.0.0
as IP, which makes it listen on all interfaces.通过使用
0.0.0.0
作为 IP 最容易实现,这使得它监听所有接口。
In your case, make the app listen on 0.0.0.0:5000
.在您的情况下,让应用程序在
0.0.0.0:5000
上侦听。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.