Reputation: 551
I have two containers added to a task definition
Node Container:
name :nodeAPI
port :exposed 5001
mongoconnection string in the env variable : mongodb://mongo [name of mongo container]
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.
Upvotes: 4
Views: 4185
Reputation: 637
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/
Upvotes: 2
Reputation: 123
If both containers are defined within the same "Task Definition" than they are able to communicate using "localhost".
In your example your NodeJs app will talk with mongo localhost:27017
Upvotes: 0
Reputation: 1
there's a security-group configuration when you running the task check whether those are open
fargate acts like a ec2 onlything is you can use a docker image so you have to do normal ec2 configs
Upvotes: 0