I’m trying to set up a RabbitMQ instance using Docker, but I’m having trouble connecting to it from another service within the same Docker Compose network. Here’s what I have so far:
Docker Compose File:
version: '3.8'
services:
rabbitmq:
image: rabbitmq:3-management
container_name: rabbitmq
ports:
- "5672:5672"
- "15672:15672"
networks:
- my-network
server:
build:
context: ./Server
ports:
- "5000:5000"
networks:
- my-network
depends_on:
- rabbitmq
worker:
build:
context: ./workers
container_name: python_worker
environment:
RABBITMQ_URL: amqp://localhost:5672
networks:
- my-network
depends_on:
- rabbitmq
networks:
my-network:
driver: bridge
I can access the RabbitMQ management interface at http://localhost:15672, but my my-service application can’t connect to RabbitMQ using the RABBITMQ_URL: amqp://rabbitmq:5672.
The error message I receive is: Error: Unable to connect to RabbitMQ server.
What I’ve Tried:
Verified that both services are on the same Docker network (my-network).
Ensured that the RABBITMQ_URL in my-service is set to amqp://rabbitmq:5672, which should be the correct internal URL.
Checked the RabbitMQ logs, but didn’t find anything helpful.
Questions:
What might be causing the connection issue between my service and RabbitMQ within Docker?
Are there any additional steps I should take to debug or configure the network settings?
Any help or insights would be greatly appreciated!