How to use rabbitmqctl to connect to the rabbitmqserver in the docker container?
Asked Answered
B

5

17

I've used docker to start my rabbitmqserver. How can I use rabbitmqctl to connect to the rabbitmqserver in the docker container?

Port 5672 has been exposed and map to the 5672 port of my host. But I still get the following error:

Status of node rabbit@m2 ...
Error: unable to connect to node rabbit@m2: nodedown
Biosphere answered 3/12, 2013 at 7:55 Comment(0)
V
8

rabbitmqctl uses Erlang Distributed Protocol (EDP) to communicate with RabbitMQ. Port 5672 provides AMQP protocol. You can investigate EDP port that your RabbitMQ instance uses:

$ netstat -uptan | grep beam
tcp        0      0 0.0.0.0:55950           0.0.0.0:*               LISTEN      31446/beam.smp  
tcp        0      0 0.0.0.0:15672           0.0.0.0:*               LISTEN      31446/beam.smp  
tcp        0      0 0.0.0.0:55672           0.0.0.0:*               LISTEN      31446/beam.smp  
tcp        0      0 127.0.0.1:55096         127.0.0.1:4369          ESTABLISHED 31446/beam.smp  
tcp6       0      0 :::5672                 :::*                    LISTEN      31446/beam.smp  

It means that RabbitMQ:

  • connected to EPMD (Erlang Port Mapper Daemon) on 127.0.0.1:4369 to make nodes able to see each other
  • waits for incoming EDP connection on port 55950
  • waits for AMQP connection on port 5672 and 55672
  • waits for incoming HTTP management connection on port 15672

To make rabbitmqctl able to connect to RabbitMQ you also have to forward port 55950 and allow RabbitMQ instance connect to 127.0.0.1:4369. It is possible that RabbitMQ EDP port is dinamic, so to make it static you can try to use ERL_EPMD_PORT variable of Erlang environment variables or use inet_dist_listen_min and inet_dist_listen_max of Erlang Kernel configuration options and apply it with RabbitMQ environment variable - export RABBITMQ_CONFIG_FILE="/path/to/my_rabbitmq.conf

my_rabbitmq.conf

[{kernel,[{inet_dist_listen_min, 55950},{inet_dist_listen_min, 55950}]}].

Or you can use RabbitMQ Management Plugin. It is more functional and simple to setup.

Vocation answered 4/12, 2013 at 9:36 Comment(1)
How can "allow RabbitMQ instance connect to 127.0.0.1:4369" be achieved with Docker? So far I have the following options: -p 55950:55950 -p 5672:5672 -p 15672:15672 -e ERL_EPMD_PORT=55950 when running the docker container, and I have epmd running on the host. But still, I can't connect with rabbitmqctl to the Rabbit instance in the container.Midis
C
10

Assuming your container is called rabbitmq and is running:

docker exec rabbitmq rabbitmqctl start_app
Cricket answered 26/11, 2014 at 23:48 Comment(0)
V
8

rabbitmqctl uses Erlang Distributed Protocol (EDP) to communicate with RabbitMQ. Port 5672 provides AMQP protocol. You can investigate EDP port that your RabbitMQ instance uses:

$ netstat -uptan | grep beam
tcp        0      0 0.0.0.0:55950           0.0.0.0:*               LISTEN      31446/beam.smp  
tcp        0      0 0.0.0.0:15672           0.0.0.0:*               LISTEN      31446/beam.smp  
tcp        0      0 0.0.0.0:55672           0.0.0.0:*               LISTEN      31446/beam.smp  
tcp        0      0 127.0.0.1:55096         127.0.0.1:4369          ESTABLISHED 31446/beam.smp  
tcp6       0      0 :::5672                 :::*                    LISTEN      31446/beam.smp  

It means that RabbitMQ:

  • connected to EPMD (Erlang Port Mapper Daemon) on 127.0.0.1:4369 to make nodes able to see each other
  • waits for incoming EDP connection on port 55950
  • waits for AMQP connection on port 5672 and 55672
  • waits for incoming HTTP management connection on port 15672

To make rabbitmqctl able to connect to RabbitMQ you also have to forward port 55950 and allow RabbitMQ instance connect to 127.0.0.1:4369. It is possible that RabbitMQ EDP port is dinamic, so to make it static you can try to use ERL_EPMD_PORT variable of Erlang environment variables or use inet_dist_listen_min and inet_dist_listen_max of Erlang Kernel configuration options and apply it with RabbitMQ environment variable - export RABBITMQ_CONFIG_FILE="/path/to/my_rabbitmq.conf

my_rabbitmq.conf

[{kernel,[{inet_dist_listen_min, 55950},{inet_dist_listen_min, 55950}]}].

Or you can use RabbitMQ Management Plugin. It is more functional and simple to setup.

Vocation answered 4/12, 2013 at 9:36 Comment(1)
How can "allow RabbitMQ instance connect to 127.0.0.1:4369" be achieved with Docker? So far I have the following options: -p 55950:55950 -p 5672:5672 -p 15672:15672 -e ERL_EPMD_PORT=55950 when running the docker container, and I have epmd running on the host. But still, I can't connect with rabbitmqctl to the Rabbit instance in the container.Midis
R
1

Just type docker exec -t rabbitmq sh Then you will get access to the terminal of your docker environment.

Once you are in, type rabbitmqctl to see if it works

Hopefully it can help you.

Rahn answered 22/4, 2020 at 6:21 Comment(1)
This did not work for me, however docker exec -ti rabbitmq bash -c "su -" did, although rabbitmqctl was an unknown command once thereSwec
M
0

I got this error trying to setup RabbitMQ on a cluster on an ubuntu and fedora machine:

el@apollo:/etc/rabbitmq$ sudo rabbitmqctl join_cluster [email protected]
Clustering node rabbit@apollo with '[email protected]' ...
Error: unable to connect to nodes ['[email protected]']: nodedown

DIAGNOSTICS
===========

attempted to contact: ['[email protected]']

[email protected]:
  * unable to connect to epmd (port 4369) on 192.168.1.8: address 
    (cannot connect to host/port)


current node details:
- node name: rabbitmqctl7233@apollo
- home dir: /var/lib/rabbitmq
- cookie hash: g0tS9zEdo7OEDSZaDTGirA==

I was able to eliminate this error by opening the 4369 and 59984 port on the 192.168.1.8 machine that is one of the slave nodes of the cluster:

el@defiant ~ $ su -
Password:
[root@defiant ~]# iptables -I INPUT -p tcp --dport 4369 --syn -j ACCEPT
[root@defiant ~]# iptables -I INPUT -p tcp --dport 59984 --syn -j ACCEPT
Medallion answered 2/9, 2014 at 3:49 Comment(1)
Can you explain why opening port 59984 helped?Chunk
R
0

Port 4369 was not enabled on firewall. When I switched firewall 'off'. Everything started working.

Retarder answered 10/8, 2016 at 10:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.