如何在 docker 容器内 运行 g运行t-connect

How to run grunt-connect within docker container

我在 docker 的 localhost:8080 上安装了 G运行t 运行 节点连接 (g运行t-contrib-connect) Web 服务器] 容器。我 运行 使用此命令的容器: $ docker run --rm -it -p 8080:8080 js1972/yeoman:v3.

在我的容器中,我 运行 g运行t 连接任务 grunt develop

我在 Mac 上,所以使用 boot2docker。 boot2docker ip 表示主机 IP 是 192.168.59.103 所以我应该在浏览器中使用 http://192.168.59.103:8080 访问连接服务器。

但是这不起作用,我只是收到一条 safari 无法连接到服务器的消息。 (请注意,当我使用 docker 网站示例中的简单 python Web 服务器时,端口转发工作得很好。)

知道这里出了什么问题吗?同样的过程在 docker 之外运行得非常好。 我有一种感觉,它与本地主机上的 运行ning 连接有关。我尝试了 --add-hosts 和 -p localhost:8080:8080 等的各种组合,但无济于事...

如果有帮助,这是我的 docker 文件和 g运行t 文件: https://dl.dropboxusercontent.com/u/7546923/Dockerfile https://dl.dropboxusercontent.com/u/7546923/Gruntfile.js

Rgds,杰森。

localhost 更改为 0.0.0.0

目前容器仅在本地接口上侦听内部 连接。使用 0.0.0.0 将告诉它监听所有接口,包括 Docker 主机连接到的接口。

修改Gruntfile连接设置中hostname的ip:

// The actual grunt server settings
connect: {
  options: {
    port: 8080,
    // Change this to '0.0.0.0' to access the server from outside.
    hostname: '0.0.0.0',
    livereload: 35729
  },

然后打开服务器并重新加载端口到 boot2docker 虚拟机:

boot2docker poweroff # vm needs to be off to modify the network settings
VBoxManage modifyvm "boot2docker-vm" --natpf1 "containergruntserver,tcp,,8080,,8080"
VBoxManage modifyvm "boot2docker-vm" --natpf1 "containergruntreload,tcp,,35729,,35729"
boot2docker up