Search code examples
node.jsreactjsdockeramazon-ecs

How to link 2 docker containers one with backend code and other with react both are on node.js


I have 2 docker containers running one with node which is my backend code and another with react build running on node, how do I link between the containers so that my react API calls are fulfilled via my node backend container.

I'm running the containers using ECS and routing using ALB, both my containers are in different target groups and the same cluster.

Actual Result:- Both the containers are running individually but there is no response to the API calls made using react. Expected Result:- API requests should be fulfilled using the other node container.


Solution

  • There is no way to link two different task definition, You should run both containers in one task definition. you can only link container if it is the single task definition otherwise you need to use service discovery or internal load balancer if the there is two different task definition and having two different target group so better to use an internal load balancer or service discovery.

    If you want to configure in the same task definition then you can refer or access the container using container name along with port. But I will not suggest docker linking in case of AWS I think such an approach is not good for production.

    One of the biggest disadvantages is that if you want to scale one container in the service, all the container will be the scale of the task definition.

    You can link this way, Go to task definition -> Container -> Networking -> just add the name of the second container as pasted in the image. enter image description here

    You can explore here and here further about service discovery and load balancer.