You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker Toolbox环境下RabbitMQ连接拒绝问题求助

Fixing RabbitMQ Connection Refusal with Docker Toolbox on Windows Home

Let’s break down why this is happening and how to fix it—since you’re on Windows Home, Docker Toolbox relies on a VirtualBox VM instead of WSL2 (only available on Pro/Edu editions), and that’s where the port mapping got tripped up.

The Root Cause

You can access the management UI at 192.168.99.101:15672 because that port was mapped correctly when starting the RabbitMQ container, but the AMQP port 5672 (the one your code uses) is likely not being forwarded from the VM to your Windows host. Here’s how to fix it step by step:

Step 1: Verify RabbitMQ Container Port Mapping

First, check if your container was started with the 5672 port mapped. Run this command in your Docker Toolbox terminal:

docker ps

Look for the PORTS column for your rabbitmq container. You should see something like 0.0.0.0:5672->5672/tcp, 0.0.0.0:15672->15672/tcp. If 5672->5672 is missing, re-run the container with the correct port mapping:

# Stop and remove the existing container (if needed)
docker stop rabbitmq && docker rm rabbitmq
# Start a new container with both ports mapped
docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:management

Step 2: Check VirtualBox Port Forwarding Rules

Docker Toolbox uses a VirtualBox VM named default to host containers. Sometimes port mapping doesn’t propagate correctly, so manually confirm:

  1. Open VirtualBox Manager
  2. Select the default VM, then click Settings > Network > Advanced > Port Forwarding
  3. Look for a rule for port 5672. If it’s missing, add a new rule:
    • Name: rabbitmq-amqp
    • Protocol: TCP
    • Host Port: 5672
    • Guest Port: 5672
    • Leave Host IP and Guest IP blank
  4. Save settings and restart the default VM (right-click > Start > Normal Start)

Step 3: Update Your Code’s Connection Settings

Now that the port is properly mapped, update your setSpecificationFactory method to use the VM’s IP (192.168.99.101) instead of localhost or 127.0.0.1—on Windows Home, localhost points to your Windows host, not the Docker VM:

private void setSpecificationFactory(ConnectionFactory factory){
    factory.setUsername("guest");
    factory.setPassword("guest");
    factory.setVirtualHost("/");
    factory.setHost("192.168.99.101"); // Use the VM's IP here
    factory.setPort(5672);
}

Step 4: Verify the Port is Accessible

Before running your code, test if the port is reachable from Windows:

  • Open PowerShell and run:
    Test-NetConnection 192.168.99.101 -Port 5672
    
    Look for TcpTestSucceeded : True in the output—if that’s there, your code should connect successfully.

Bonus: Check RabbitMQ Internal Listening

If the above steps don’t work, confirm RabbitMQ is actually listening on port 5672 inside the container:

  1. Run this command to enter the container shell:
    docker exec -it rabbitmq bash
    
  2. Check listening ports:
    netstat -tulpn | grep 5672
    
    You should see a line showing rabbitmq-server listening on 0.0.0.0:5672. If not, restart the RabbitMQ service inside the container:
    rabbitmqctl stop && rabbitmq-server -detached
    

内容的提问来源于stack exchange,提问作者Jacek Andrzejczyk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 09:37:34