Search code examples
dockercontainersdevopsamazon-ecs

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?


Solution

  • 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