访问码头工人内部的咕噜声服务

时间:2016-09-23 07:31:42

标签: docker gruntjs yeoman

我制作了2个泊坞窗图像(nginx,yeoman)和映射端口,如下所示。

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                           NAMES
3a71ee900cc0        webserver:0.1       "nginx"             About an hour ago   Up About an hour    443/tcp, 0.0.0.0:8080->80/tcp   webserver
af57b93ca326        silarsis/yeoman     "/bin/bash"         About an hour ago   Up About an hour    0.0.0.0:9000->9000/tcp          yeoman

进入自耕农码头制造咕噜声服务器。

yeoman_docker$ yo  ..scafolding stuff  
yeoman_docker$ ls  
Gruntfile.js README.md  app  bower.json  bower_components  node_modules  package.json  test  
yeoman_docker$ grunt serve 
Running "serve" task


    Done, without errors.


    Execution Time (2016-09-23 07:20:28 UTC-0)
    loading tasks                5ms  ▇▇▇▇▇▇▇ 19%
    loading grunt-contrib-copy  13ms  ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 50%
    copy:styles                  8ms  ▇▇▇▇▇▇▇▇▇▇▇ 31%
    Total 26ms

Running "autoprefixer:server" (autoprefixer) task Autoprefixer's process() method is deprecated and will removed in next major release. Use postcss([autoprefixer]).process() instead File .tmp/styles/main.css created.

Running "connect:livereload" (connect) task Started connect web server on http://localhost:9000

Running "watch" task Waiting...

保持此SSH以维护grunt服务。 Nginx可从本地访问(127.0.0.1:8080)但grunt无法访问(127.0.0.1:9000)。在本地和docker中制作grunt服务器有什么区别吗?我该怎么办呢?

似乎grunt服务器不在本地。

$ telnet 127.0.0.1 9000
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Connection closed by foreign host.

$ netstat -ant
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 10.0.8.1:53             0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp6       0      0 :::9000                 :::*                    LISTEN
tcp6       0      0 :::8080                 :::*                    LISTEN
tcp6       0      0 :::21                   :::*                    LISTEN
tcp6       0      0 :::22                   :::*                    LISTEN
tcp6       0      0 127.0.0.1:9000          127.0.0.1:39682         TIME_WAIT

1 个答案:

答案 0 :(得分:1)

问题是yeoman容器中的连接服务器侦听容器内的localhost:

Running "connect:livereload" (connect) task Started connect web server on http://localhost:9000

使用docker创建端口绑定时,docker容器内的服务必须侦听主机0.0.0.0,而不是localhost。您需要更新gruntfile.js,以便将服务器侦听连接到0.0.0.0