contactmatt
contactmatt

Reputation: 18600

Running multiple docker containers listening on same port for RabbitMQ messages

I'm running a RabbitMQ container using the following command:

docker run --name sl-rabbitmq-mgmt-dev --publish=15672:15672/tcp --publish=5672:5672/tcp --hostname=rabbitmq --detach rabbitmq:3-management

Port 15672 is for the management console, the main port for communication is 5672

I have multiple .NET Core docker images that listen/subscribe to port 5672 to listen for incoming messages for a queue, and push messages to a queue.

There can/will be multiple instances ("workers") of a .dll running. Running one instance is fine for local development, but multiple will be running in PROD.

enter image description here

When I attempt to run my docker image of the .dll (i.e. Process1.dll)

docker run --rm --publish=5672:5672/tcp --detach process1:latest

it indicates that a container is already bound to that port on 0.0.0.0:/5672

I'm assuming a docker-compose file will be needed to accomplish what I'm setting out for.

How can I accomplish running these multiple containers on the same port?

Upvotes: 1

Views: 2053

Answers (2)

David Maze
David Maze

Reputation: 158656

The RabbitMQ workflow is that the broker needs to listen on port 5672. Producers and consumer need to make outbound connections to that port on the broker, but they don’t themselves need to accept inbound connections.

This means that you can remove the --publish option from your worker containers. They will still be able to make outbound connections to RabbitMQ, and you won’t have the port conflict.

Upvotes: 1

Meiram Chuzhenbayev
Meiram Chuzhenbayev

Reputation: 906

It's not possible to run multiple containers on the same port on the host. Or you need change your solution. For example change port.

Upvotes: 0

Related Questions