Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make containers communicate with each other in ECS without link and port mapping?

I didn't find a solution for that two containers in separate task definitions can communicate with each other. Therefore, I follow the answer to link the two containers in the same task definitions which works well.Thanks for the answer first.

However, when I read the ECS documentation, I find the following paragraph that is confusing me:

Containers that are collocated on a single container instance may be able to communicate with each other without requiring links or host port mappings. Network isolation is achieved on the container instance using security groups and VPC settings.

But I didn't be able to find further documentation how to achieve this. I knew that docker community try to use --network and deprecated the --link. I'm not sure if AWS makes some change to also enable these somehow.

Would someone can help me understand how to achieve that? Because the container name and IP is always dynamic assigned by ECS, how can I communicate from one container to another container if in different task definition without link and port mappings?

like image 264
Zingoer Avatar asked Jan 09 '17 21:01

Zingoer


People also ask

How containers communicate with each other in ECS?

The link parameter allows containers to communicate with each other without the need for port mappings. Only supported if the network mode of a task definition is set to bridge. The name:internalName construct is analogous to name:alias in Docker links.

Can 2 containers communicate with each other?

If you are running more than one container, you can let your containers communicate with each other by attaching them to the same network. Docker creates virtual networks which let your containers talk to each other. In a network, a container has an IP address, and optionally a hostname.

Can ECS tasks talk to each other?

You can allow your tasks to communicate with each other using Service discovery. Service discovery helps manage HTTP and DNS namespaces for your Amazon ECS services. Note: Service discovery supports the A and SRV DNS record types.


1 Answers

Based on your use case you can utilized service discovery feature of ECS, service discovery will give an endpoint(url) to communicate between different services privately.

In service discovery ECS take care of updating dynamic IP and port of containers to DNS record, every time a new task is started or stopped.

Reference Doc: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-discovery.html

like image 55
Mangal Avatar answered Oct 03 '22 18:10

Mangal