I created rabbitmq container by running the below command
docker run -d --hostname My-rabbit --name test-rabbit -p 15672:15672 rabbitmq:3-management
Created a user called userrabbit and given the permissions as below
rabbitmqctl add_user userrabbit password
rabbitmqctl set_user_tags userrabbit administrator
rabbitmqctl set_permissions -p / userrabbit ".*" ".*" ".*"
IP of this(test-rabbit) is 172.17.0.3
I created one more container(172.17.0.4) in which my application is running and in which I need to provide the url of the rabbitmq and I've provided the url as below
transport_url = rabbit://userrabbit:[email protected]:15672/
In the logs of container(172.17.0.4), it's showing as
AMQP server 172.17.0.3:15672 closed the connection. Check login credentials: Socket closed
But I"m able to ping the RabbitMq from the container(172.17.0.4) with the same credentials as shown below
curl -i -u userrabbit:password http://172.17.0.3:15672/api/whoami
HTTP/1.1 200 OK
vary: Accept-Encoding, origin
Server: MochiWeb/1.1 WebMachine/1.10.0 (never breaks eye contact)
Date: Tue, 14 Feb 2017 17:06:39 GMT
Content-Type: application/json
Content-Length: 45
Cache-Control: no-cache
{"name":"userrabbit","tags":"administrator"}
2 things...
it's port 5672 for the transport_url
the 15672 port you listed is the web admin console
you need to network you containers together via docker networking.
easiest way is with the --link option, provided to the second container at run time.
docker run --link test-rabbit:test-rabbit (... other options here)
by adding the --link test-rabbit:test-rabbit option, your application will be able to see test-rabbit as a valid network name with ip address.
with these two fixes, your transport_url then becomes this
transport_url = rabbit://userrabbit:password@test-rabbit:5672/
using --link is the easiest way to start, but isn't very scalable.
docker-compose makes it really easy to add links between containers
and you can also create custom docker networks via command-line tools and docker-compose, to connect containers together. that's more work, but better long-term.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With