docker-library / rabbitmq

Docker Official Image packaging for RabbitMQ
http://www.rabbitmq.com/
MIT License
785 stars 417 forks source link

Unable to connect to RabbitMQ via localhost or 127.0.0.1 #645

Closed zN3utr4l closed 1 year ago

zN3utr4l commented 1 year ago

Describe the bug

I am encountering an issue when trying to connect to RabbitMQ using localhost or 127.0.0.1. I am running it within a Docker container that is on the same network as RabbitMQ server. However, I can only connect using the container Docker's IP address.

I have checked the output of the "rabbitmq-diagnostics listeners" command and noticed that RabbitMQ is configured to listen on all IPv6 interfaces. However, it seems that it is not configured to listen on IPv4 interfaces such as localhost or 127.0.0.1.

Interface: [::], port: 15692, protocol: http/prometheus, purpose: Prometheus exporter API over HTTP
Interface: [::], port: 25672, protocol: clustering, purpose: inter-node and CLI tool communication
Interface: [::], port: 5672, protocol: amqp, purpose: AMQP 0-9-1 and AMQP 1.0
Interface: [::], port: 15672, protocol: http, purpose: HTTP API

I have tried modifying the RabbitMQ configuration to include localhost and 127.0.0.1 as listening interfaces in the configuration file, but without success. I used the following configurations:

listeners.tcp.default = 5672
listeners.ssl.default = 5671
loopback_users.guest = true

or

listeners.tcp.1= 127.0.0.1:5672
listeners.ssl.1= 127.0.0.1:5671
loopback_users.guest = true
/code # python rabbitmqadmin -H localhost -u guest -p guest list vhosts
*** Could not connect: [Errno 111] Connection refused

/code # python rabbitmqadmin -H 172.20.7 -u guest -p guest list vhosts
+------+----------+
| name | messages |
+------+----------+
| /    |          |
+------+----------+

Describe the bug

I am encountering an issue when trying to connect to RabbitMQ using localhost or 127.0.0.1. I am running it within a Docker container that is on the same network as RabbitMQ server. However, I can only connect using the container Docker's IP address.

I have checked the output of the "rabbitmq-diagnostics listeners" command and noticed that RabbitMQ is configured to listen on all IPv6 interfaces. However, it seems that it is not configured to listen on IPv4 interfaces such as localhost or 127.0.0.1.

Interface: [::], port: 15692, protocol: http/prometheus, purpose: Prometheus exporter API over HTTP
Interface: [::], port: 25672, protocol: clustering, purpose: inter-node and CLI tool communication
Interface: [::], port: 5672, protocol: amqp, purpose: AMQP 0-9-1 and AMQP 1.0
Interface: [::], port: 15672, protocol: http, purpose: HTTP API

I have tried modifying the RabbitMQ configuration to include localhost and 127.0.0.1 as listening interfaces in the configuration file, but without success. I used the following configurations:

listeners.tcp.default = 5672
listeners.ssl.default = 5671
loopback_users.guest = true

or

listeners.tcp.1= 127.0.0.1:5672
listeners.ssl.1= 127.0.0.1:5671
loopback_users.guest = true
/code # python rabbitmqadmin -H localhost -u guest -p guest list vhosts
*** Could not connect: [Errno 111] Connection refused

/code # python rabbitmqadmin -H 172.20.7 -u guest -p guest list vhosts
+------+----------+
| name | messages |
+------+----------+
| /    |          |
+------+----------+
/code # python rabbitmqadmin -H 127.0.0.1 -u guest -p guest list vhosts
*** Could not connect: [Errno 111] Connection refused

image

/code # python rabbitmqadmin -H 127.0.0.1 -u guest -p guest list vhosts *** Could not connect: [Errno 111] Connection refused



![image](https://github.com/docker-library/rabbitmq/assets/73225008/83298738-78a2-4589-b55d-d94a03215145)
zN3utr4l commented 1 year ago

the problem occurred while using this library https://github.com/revsys/django-health-check/issues/369#issue-1748036211