ECS task dynamic port mapping and docker communication

Viewed 173

I have a TaskDefinition that defines 2 docker images, and these 2 docker images needs to communicate between each other.

The first docker container, let's call it Frontend, calls the second docker container, Backend, using its name and port. Which means, inside the Frontend container there is a call to the Backend container using container_name:container_port.

Using dynamic port mapping does not allow me to do that, because I can't find the exposed port of the Backend container. An idea would be to find it with some script and then pass it to the Frontend container, but that seems very hacky.

Using static port mapping, I can achieve that. However, if one of the ECS task fail, a new one will be spun-up and it is very likely that this new task will fail to run, because it will be placed on an EC2 instance where the port are still exposed (so, it will fail to bind the docker port to the host).

Kind of the same issue is described here as well.

What could be the way to achieve such configuration?

0 Answers
Related