2016-04-05 68 views
0

我在centos6.7码头工具集合中运行jboss5。访问码头集装箱内的jboss 8080端口

JBoss上运行使用run.sh -b 0.0.0.0命令 集装箱使用docker run -i -t -p 8080:8080 my/jboss /bin/bash

这是我在容器看到运行

[[email protected] bin]# netstat -alnt 
Active Internet connections (servers and established) 
Proto Recv-Q Send-Q Local Address    Foreign Address    State  
tcp  0  0 0.0.0.0:8009    0.0.0.0:*     LISTEN   
tcp  0  0 0.0.0.0:8080    0.0.0.0:*     LISTEN  
tcp  0  0 0.0.0.0:8083    0.0.0.0:*     LISTEN 

这是我在主机上看到

15:04:17:(~)$ sudo docker ps 
[sudo] password for c0rp: 
CONTAINER ID  IMAGE     COMMAND    CREATED    STATUS    PORTS     NAMES 
e44f2bbab31a  my/jboss   "/bin/bash"   4 hours ago   Up 4 hours   0.0.0.0:8080->8080/tcp thirsty_franklin 

当我试图从主机访问jboss应用程序通过localhost:8080我看到ERROR 404: Not Found.

当我检查本地主机:从容器内使用wget 8080我看到同样的错误ERROR 404: Not Found.

一切都OK了,如果我使用的容器的IP地址。问题是我如何将主机localhost:8080绑定到容器ip_address:8080?

回答

1

localhost127.0.0.1的别名。这个地址用于环回。这意味着您的请求将返回到网络OSI模型层上的同一台机器(通过lo0接口ifconfig命令)。但是你可以使用请求localhost访问您的容器:

  1. !!!非常-非常肮脏的黑客!不要使用它。只是为了了解localhost问题。您可以编辑hosts文件(如适用于Mac):

    sudo nano /private/etc/hosts

    你会看到这样的事情:

    127.0.0.1  localhost 
    255.255.255.255 broadcasthost 
    ::1    localhost 
    

    你容器的IP只需更换127.0.0.1。我在重复:只是为了解localhost

  2. 您可以在您的localhost机器上运行NGINX实例。您可以对其进行配置,以便将所有请求从localhost:8080发送到containerIp:8080(不带任何路由的任何配置的最佳变体)

相关问题