AWS ECS containers are not connecting but works perfectly in my local machine AWS ECS containers are not connecting but works perfectly in my local machine docker docker

AWS ECS containers are not connecting but works perfectly in my local machine


What kind of Docker Network mode are you using(Brdige/Host) on ECS?. I don't think localhost will work properly on ECS containers. I had same issue so I used private IP or DNS name of EC2 host for my communication as temp testing purpose. Ex - http://10.0.1.100:8081.

Note - Please make sure to give security group rule to allow 8081 traffic from within EC2(Edit EC2 security group to allow 8081 from same sgid as source).

For Production deployments, I would recommend to use a service discovery to identify the backend service(Consul by Hashicorp) or AWS Private Service Discovery on ECS.


-- Update --

Since you are running both containers under same task def(under same ECS service), so typically ECS will bring both docker containers on same host. Do something like following.

  1. By default ECS brings containers using Bridge mode on Linux.
  2. You should be able to have each containers communicate using Docker Gateway IP - 172.17.0.1 on Linux. So for your case, try configuring http://172.17.0.1:8081