【问题标题】:Connection refused when try to connect http server in docker daemon container尝试在 docker daemon 容器中连接 http 服务器时连接被拒绝
【发布时间】:2015-05-24 09:45:58
【问题描述】:

我正在使用 boot2docker。我在守护进程模式下运行一个镜像,它在端口 3000 启动 grunt 服务器。这是我用来启动它的命令。

该图像已经暴露了 3000 端口

docker run -d -P --name dummy image_name grunt server
docker ps
3af4ba19c539        image_name:latest   "grunt server"      54 minutes ago      Up 54 minutes       0.0.0.0:45000->3000/tcp   dummy

然后运行到同一个容器中以“卷曲”网络服务器。

docker exec -it 3af4ba19c539 /bin/bash 
curl localhost:3000 

获取 html。

但是,当我尝试在我的 mac 电脑中连接它时。它说“连接被拒绝”。

curl $(boot2docker ip):45000
//curl: (7) Failed connect to 192.168.59.103:45000; Connection refused

我尝试使用 VBoxManage 来解决这个问题,但它也不起作用

VBoxManage modifyvm "boot2docker-vm" --natpf1 "tcp-port45000,tcp,,45000,,45000"

我想知道如何解决这个问题。非常感谢提前

【问题讨论】:

  • 在您进行 modifyvm 时容器是否在运行?因为如果是,则需要 controlvm:请参阅 stackoverflow.com/a/29998490/6309
  • 登录容器并发布netstat -ant的输出

标签: docker boot2docker


【解决方案1】:

我需要查看您的应用程序的源代码才能确定,但​​我敢打赌您已经绑定到应用程序中的本地环回接口(@98​​7654321@ 或localhost)。如果您改为绑定到0.0.0.0 来监听所有接口,您应该会发现它可以从外部访问。

【讨论】:

    猜你喜欢
    • 2019-10-20
    • 2019-02-09
    • 1970-01-01
    • 2019-03-30
    • 1970-01-01
    • 2021-11-16
    • 2021-07-03
    • 2016-11-28
    • 1970-01-01
    相关资源
    最近更新 更多