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?
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With