2
votes

I am starting a docker container with RabbitMQ for testing purposes. I would like to start a second container which runs a short command and checks that the Rabbitmq is actually running. The second container should block my build pipeline until it has determined that RabbitMQ has successfully started in the first container.

How can I specify to rabbitmqctl which hostname to use to get the status of RabbitMq? I am linking the two containers together via docker so port issues should not be a problem.

Example:

rabbitmqctl -n rabbitmq status # does not work, prints diagnostic info

Status of node rabbitmq@rabbitmq ... Error: unable to perform an operation on node 'rabbitmq@rabbitmq'. Please see diagnostics information and suggestions below.

Most common reasons for this are:

  • Target node is unreachable (e.g. due to hostname resolution, TCP connection or firewall issues)
  • CLI tool fails to authenticate with the server (e.g. due to CLI tool's Erlang cookie not matching that of the server)
  • Target node is not running

In addition to the diagnostics info below:

DIAGNOSTICS

attempted to contact: [rabbitmq@rabbitmq]

rabbitmq@rabbitmq: * connected to epmd (port 4369) on rabbitmq * epmd reports: node 'rabbitmq' not running at all other nodes on rabbitmq: [rabbit] * suggestion: start the node

Current node details: * node name: rabbitmqcli52@e3ea1e73df02 * effective user's home directory: /var/lib/rabbitmq * Erlang cookie hash: AB9AFN3zvcyAWBl6ZVVOJw==

3
What diagnostic info does it print? Have you tried rabbit@rabbitmq? Is rabbitmq your container's name as well as the image's name?vmonteco
@vmonteco I updated my question.lanoxx
Have you tried docker exec -ti rabbitmq rabbitmqctl status? If no please try and post the output.vmonteco
@vmonteco Yes, that works.lanoxx

3 Answers

0
votes

Your second container needs to be aware of the first one:

docker run --link rabbitmq ...

The host will be available now from inside the container:

$ grep rabbitmq /etc/hosts
172.17.0.2  rabbitmq 01ad3098b423

$ ping rabbitmq
PING rabbitmq (172.17.0.2): 56 data bytes
64 bytes from 172.17.0.2: seq=0 ttl=64 time=0.073 ms

Keep in mind container linking is deprecated in favor of custom networks.

0
votes

First create a network so that you can assign IPs: docker network create --subnet=172.18.0.0/16 mynet1

I'm going to assume you use rabbitmq management container, and for and I'll call it (hostname) rab1. I'll give the name ubuntu1 to the other container from which you want to access rab1.So first start rab1 and add ubuntu1 to hosts file:

docker run -d --net mynet1 --ip 172.18.0.11 --hostname rab1 --add-host ubuntu1:172.18.0.12 --name rab1con -e RABBITMQ_ERLANG_COOKIE='secret cookie here' rabbitmq:3-management

And after that start the ubuntu1con with hostname ubuntu1

docker run -d --net mynet1 --ip 172.18.0.12 --hostname ubuntu1 --add-host rab1:172.18.0.11 --name ubuntu1con ubuntu

Now when you go into ubuntu1con you are able to access rab1 by name or ip address.

0
votes

Assuming the two containers are linked/networked properly, can ping each other, and the Rabbitmq client rabbitmqctl is installed in the second container, the following should work:

docker exec -it <second container's name or ID> rabbitmqctl -n rabbit@rabbitmq status 

Pass --hostname rabbitmq to docker run when starting the rabbitmq container, and make sure that hostname -s inside the rabbitmq container prints rabbitmq.

If the error is still seen, add <IP address of rabbitmq container> rabbitmq in /etc/hosts of the second container and re-try.

https://docs.docker.com/network/network-tutorial-standalone/#use-user-defined-bridge-networks has info about how to network two containers so that they can ping each other on the same network.