无法访问映射到docker容器端口的主机上的端口

时间:2016-10-25 05:04:50

标签: docker dockerfile

我已使用命令

启动了一个docker容器
sudo docker run -it -P -d plcdimage 

使用具有EXPOSE 8080指令的Dockerfile构建映像.Container运行一个jboss服务器,其上部署了一个应用程序。端口映射是:

Command: sudo docker port be1837e849dc

Output: 8080/tcp -> 0.0.0.0:32771

当我尝试使用url从映射的主机端口访问容器中jboss上运行的Web应用程序时:

http://IPAddressOfHost:32771/

我收到连接拒绝错误。以下是命令" netstat -tulpn"的结果。

(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -               
tcp6       0      0 :::9999                 :::*                    LISTEN      -               
tcp6       0      0 :::22                   :::*                    LISTEN      -               
tcp6       0      0 :::32771                :::*                    LISTEN      -               
udp        0      0 0.0.0.0:68              0.0.0.0:*                           -        

我尝试使用telnet hostip 32771,它也会导致连接被拒绝。

Docker version 1.12.1  
build 23cf638

可能的原因是什么?

提前致谢

1 个答案:

答案 0 :(得分:1)

我发现在容器内运行的jboss服务器没有监听0.0.0.0。执行此操作的一个选项是,启动独立服务器时使用-b 0.0.0.0。

/bin/standalone.sh -b 0.0.0.0