我有一个运行 java 进程的 docker 容器,我试图连接到在我的本地主机上运行的 rabbitmq。

以下是我到目前为止所做的步骤:

在我的本地机器上(运行 Docker 版本 1.13.0-rc3 的 macbook,在关闭防火墙的情况下构建 4d92237)

  • 我已经更新了我的 rabbitmq_env.conf 文件以删除 RABBITMQ_NODE_IP_ADDRESS,所以我没有通过 localhost 进行连接,并且我有一个管理员 rabbitmq 用户。 (不尝试访客用户)
  • 我在本地机器上通过 telnet 进行了测试,没有问题 telnet <local-ip> 5672

  • 在我的 docker 容器里面
  • 能够 ping local-ip 和 curl rabbitmq admin apicurl -i -u username:password http://local-ip:15672/api/vhosts成功返回

    [{"name":"/","tracing":false}]

  • 当我尝试从容器内部远程登录时,我得到

    "Connection closed by foreign host"

  • 查看 rabbitmq.logs

    =错误报告====
    关闭 AMQP 连接 <0.30526.1> (local-ip:53349 -> local-ip:5672):
    {handshake_timeout,handshake}

  • 我的 java stacktrace 有帮助

    Caused by: java.net.ConnectException: Connection refused (Connection >refused) at java.net.PlainSocketImpl.socketConnect(Native Method) at >java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) at >java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.>java:206) at >java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:589) at >com.rabbitmq.client.impl.FrameHandlerFactory.create(FrameHandlerFactory.ja>va:32) at >com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory.newCon>nection(RecoveryAwareAMQConnectionFactory.java:35)


    docker network inspect bridge

    [ { "Name": "bridge", "Id": "716f935f19a107225650a95d06eb83d4c973b7943b1924815034d469164affe5", "Created": "2016-12-11T15:34:41.950148125Z", "Scope": "local", "Driver": "bridge", "EnableIPv6": false, "IPAM": { "Driver": "default", "Options": null, "Config": [ { "Subnet": "172.17.0.0/16", "Gateway": "172.17.0.1" } ] }, "Internal": false, "Attachable": false, "Containers": { "9722a49c4e99ca5a7fabe56eb9e1c71b117a1e661e6c3e078d9fb54d7d276c6c": { "Name": "testing", "EndpointID": "eedf2822384a5ebc01e5a2066533f714b6045f661e24080a89d04574e654d841", "MacAddress": "02:42:ac:11:00:02", "IPv4Address": "172.17.0.2/16", "IPv6Address": "" } }, "Options": { "com.docker.network.bridge.default_bridge": "true", "com.docker.network.bridge.enable_icc": "true", "com.docker.network.bridge.enable_ip_masquerade": "true", "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0", "com.docker.network.bridge.name": "docker0", "com.docker.network.driver.mtu": "1500" }, "Labels": {} } ]



    我错过了什么?

    请您参考如下方法:

    对我来说这很好用!

    I have been installed the image docker pull rabbitmq:3-management



    并运行
    docker run -d --hostname haroldjcastillo --name rabbit-server -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin2017 -p 5672:5672 -p 15672:15672 rabbitmq:3-management 
    

    the most important is to add the connection and management ports -p 5672:5672 -p 15672:15672



    docker 见
    docker-machine ip 
    

    在我的情况下返回:
    192.168.99.100 
    

    Go to management http://192.168.99.100:15672

    For Spring Boot you can configure this or works good for another connections


    spring.rabbitmq.host=192.168.99.100 
    spring.rabbitmq.username=admin 
    spring.rabbitmq.password=admin2017 
    spring.rabbitmq.port=5672 
    

    最良好的祝愿


    评论关闭
    IT干货网

    微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!