简体   繁体   中英

AWS ECS - Can't connect to RabbitMQ EC2 instance from ECS container instance on the same subnet

I am building an application where I will have multiple Docker services running on ECS container instance communicating with each other via RabbitMQ which runs on a separate EC2 instance in the same VPC and in the same subnet. The RabbitMQ security group is configured to allow all the traffic from that subnet.

However, when I start the service and it tries to connect to RabbitMQ I get an error saying ECONNREFUSED 127.0.0.1:5672 . This is the url that I am using t connect amqp://username:password@ipaddr:5672/?heartbeat=60 . The network mode for Docker is default/Bridge .

I am setting the connection url via an environment variable and I did ssh into the ECS container instance and then docker exec -it cntainerID /bin/bash and was able to verify that the environment variable is set.

127.0.0.1 is not the IP address of the EC2 RabbitMQ server. That address will always point to what ever machine the code is running on, it is called "localhost".

You need to be using the private IP of the EC2 server running RabbitMQ.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM