It's a question really, but I can't add labels to mark is as that, so just have to set an issue, apologies.
Could you provide with me an example of a docker-compose.yml file that will work, and what the amqp string would be to connect to that container from another container in the same stack?
I'm having one hell of a time trying to get my other container to connect, but it's constantly giving me connection refused. I have tried a lot of different ways now, starting to go a bit nuts.
I'm obviously doing something stupid :-(
Regards
Matt
Hi Matt,
I think I have something to help you, although I am a beginner myself. I was setting up a swarm cluster with a multi-host overlay network (which is AFAIK automatically done by docker compose if you are connected to a swarm).
The problem I had (and which I could not solve) is to connect to the RabbitMQ service I deployed. I did not dive deeper but right now linking my services to the RabbitMQ service is needed.
Here is my docker compose file. It is located in the folder test so every service will be named "test_rabbitMq_XX"
version: '2'
services:
rabbitMq:
image: rabbitmq:3-management
ports:
- "8080:15672"
- "5672:5672"
- "5671:5671"
environment:
RABBITMQ_DEFAULT_PASS: pass
RABBITMQ_DEFAULT_USER: user
RABBITMQ_DEFAULT_VHOST: vhost
client:
image: some/image
links:
- rabbitMq
and to connect to the service you from the client you use a connection string such as amqp://user:pass@rabbitMq:5672/vhost.
I assigned a different default user and a different vhost, because AFAIK guest:guest is only allowed to login from localhost and specifying the default vhost / can be tricky as well. If this works you can start removing the environment variables and test again ;)
Regards
Martin
Hi Martin
Thanks for replying.
What I ended up doing is creating our own image of rabbit, and then running some setup commands on that image using an init.sh file called from the Dockerfile.
We then uploaded that image to our docker hub repository and now use that.
init.sh
#!/bin/sh
# Create Default RabbitMQ setup
( sleep 10 ; \
# Create users
# rabbitmqctl add_user <username> <password>
# Set user rights
# rabbitmqctl set_user_tags <username> <tag>
# Create vhosts
# rabbitmqctl add_vhost <vhostname>
# Set vhost permissions
# rabbitmqctl set_permissions -p <vhostname> <username> ".*" ".*" ".*"
) &
rabbitmq-server $@
We then use tags on the image to add different variables for different instances of the image, so we can reuse it to build multiple containers.
Hope this helps in some way
Thanks again for getting back to me.
Matt
Most helpful comment
Hi Martin
Thanks for replying.
What I ended up doing is creating our own image of rabbit, and then running some setup commands on that image using an init.sh file called from the Dockerfile.
We then uploaded that image to our docker hub repository and now use that.
init.sh
We then use tags on the image to add different variables for different instances of the image, so we can reuse it to build multiple containers.
Hope this helps in some way
Thanks again for getting back to me.
Matt