Federico Domenici
Federico Domenici

Reputation: 21

Connect ECS task with Service Discovery

here my situation: I have a docker-compose with some container configured in the same networks. I need that all the containers can communicate with all others, and some of these container had an environment where i need to set the endpoint of another one, like this example:

containerA:
  image: imageA:0.0.1
  port:
    - "8080"
  network:
    - net1

containerB:
  image: imageB:0.0.1
  environments:
    - BRIDGE: http://containerA:8080
  network:
    - net1

I need now to translate this docker-compose to an ECS Service (one Task for containerA and one Task for containerB). I'm using ecs-cli without any problem, i can create a Cluster, run services with Fargate, run all the task inside the same VPC, using the same Security Group, and i enabled Service Discovery for all the ECS Services, using the same namespace for all (so i have containerA.namespace1 and containerB.namescape1). But i have a problem in the connection between this two tasks: i try so set:

BRIDGE: http://containerA:8080
BRIDGE: http://containerA.namespace1:8080
BRIDGE: http://containerA.namespace1.local
BRIDGE: http://containerA.namespace1.local:8080

but all this options doesn't work. I try a "temp" solution for this problem using the public ip generated from taskA, but if i update the task A, the public IP rightly changes and i need redeploy also taskB. So, the question is: how i can use "hostname" so i can connect to the name of the service and not to the public ip of the task? thanks for any suggestion

Upvotes: 2

Views: 900

Answers (1)

mreferre
mreferre

Reputation: 6073

[Update based on the thread] The answer originally provided below assumes you are open to evaluate an alternative tool to deploy your compose file on ECS.

It is very likely that if you use the native docker compose integration with ECS you can up your compose file and achieve what you want without you doing nothing special.

You can read more about how to do that here. BTW the service discovery mechanism you are using is identical to the discovery mechanism I need in the application I have used in the blog. I am fairly confident that it will work for you.

Upvotes: -1

Related Questions