【问题标题】:Cannot access port on host mapped to docker container port无法访问映射到 docker 容器端口的主机上的端口
【发布时间】:2016-10-25 05:04:50
【问题描述】:

我已经使用命令启动了一个 docker 容器

sudo docker run -it -P -d plcdimage 

该镜像是使用具有指令 EXPOSE 8080 的 Dockerfile 构建的。容器运行一个 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

这可能是什么原因?

提前致谢

【问题讨论】:

  • 首先要检查的是你的容器是否真的在监听8080端口。你可以用docker inspect获取你的容器的IP地址,然后尝试从主机浏览到http://[container-ip]:8080
  • sudo docker ps的结果是什么?

标签: docker dockerfile


【解决方案1】:

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

/bin/standalone.sh -b 0.0.0.0

【讨论】:

    猜你喜欢
    • 2020-02-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-01
    • 1970-01-01
    • 2016-04-30
    • 1970-01-01
    相关资源
    最近更新 更多