gpt4 book ai didi

docker - 从 Docker 容器到本地主机的 Rabbitmq 连接被拒绝

转载 作者:行者123 更新时间:2023-12-04 11:48:29 26 4
gpt4 key购买 nike

我有一个运行 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

    最良好的祝愿

    关于docker - 从 Docker 容器到本地主机的 Rabbitmq 连接被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41089268/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com