Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make two containers connectable in AWS ECS Fargate?

I have two containers added to a task definition

  1. Node Container:

    name :nodeAPI
    port :exposed 5001
    mongoconnection string in the env variable : mongodb://mongo  [name of mongo container]
    
  2. Mongo container:

    name :mongo
    port :exposed 27017
    

The node container is not able to connect to Mongo when I run this task. I am using Fargate and network as awsvpc.

  1. How do I fix this?
  2. How do I make it work running them from separate task definitions?
like image 964
Tanmay Bhattacharya Avatar asked Oct 26 '25 23:10

Tanmay Bhattacharya


1 Answers

As every task in Fargate gets it own ENI, therefore correct way to communicate between containers in same task definition is calling local loopback 127.0.0.1 or localhost.

For example:

First Container will be able to communicate to second container using 127.0.0.1:<port of second container> as address and second container can communicate to First container using 127.0.0.1:<port of first container>

This is very well explained in AWS Blog: https://aws.amazon.com/blogs/compute/task-networking-in-aws-fargate/

like image 165
Mangal Avatar answered Oct 28 '25 17:10

Mangal