我的设置如下:
Host: Win10
Guest: Ubuntu 15.10 (clean install, only docker and nodejs are added)
Base image: https://hub.docker.com/r/microsoft/aspnet/ 1.0.0-beta8-coreclr在来宾内部,我安装了Docker并创建了映像(在上面的映像中添加了示例webapp,使用yeoman )。当我在容器中运行映像时,我可以成功地使用来自linux的容器IP (例如172.17.0.2)对容器IP进行平分。
$sudo docker run -d -p 80:5000 --name web myapp
$sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' "web"
172.17.0.2
$ping 172.17.0.2
PING 172.17.0.2 (172.17.0.2) 56(84) bytes of data.
64 bytes from 172.17.0.2: icmp_seq=1 ttl=64 time=0.060 ms
1 packets transmitted, 1 received, 0% packet loss, time 999ms
$curl 172.17.0.2:80
curl: (7) Failed to connect to 172.17.0.2 port 80: Connection refused我还可以连接到容器并执行类似ping之类的命令,但是从linux机器( VirtualBox中的来宾,docker的主机),我无法访问容器中托管的web应用程序,如上面所示。我尝试了几种方法,如映射到主机IP地址等,但没有一种方法有效。有谁能想到从哪里开始呢?该问题是否来自于VirtualBox计算机中安装的对接器?
提前谢谢你。
编辑:以下是容器中的日志:
Could not open /etc/lsb_release. OS version will default to the empty string.
Hosting environment: Production
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.发布于 2015-11-11 01:33:12
您的命令告诉Docker本质上是从Linux来宾的端口80到容器的5000端口的代理请求。因此,您尝试的curl命令不起作用,因为您正在容器上尝试端口80,而容器本身有一个侦听端口5000的服务。
要直接连接到容器,您可以使用(在Linux来宾上):
curl 172.17.0.2:5000要通过Linux来宾上发布的端口访问(从您的主机):
curl (Linux guest IP)或者(来自Linux来宾):
curl localhost编辑:,这也将证明是有问题的:
Now listening on: http://localhost:5000您将希望容器中的应用程序绑定到所有接口(0.0.0.0),以便它侦听容器分配的IP。使用localhost,它将无法访问。
您可能会发现这个示例很有用:
https://github.com/aspnet/Home/blob/dev/samples/1.0.0-beta8/HelloWeb/project.json
这一行指定应用程序绑定到端口5004上的所有接口(使用"*"):
21 "kestrel": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://*:5004"您需要类似的配置。
https://stackoverflow.com/questions/33640133
复制相似问题