I have a docker-compose v3 file (see below) that I use to deploy and test my development progress locally. It works like a charm - on my machine. As you can see I am using the default bridge
network type for internal service HTTP calls. This enables me to seamlessly "connect" the services defined in my docker-compose file, just by using service name defined in docker-compose file as its domain name, like in the example bellow.
Now I want to make use of the same docker-compose file to deploy in AWS ECS (using Fargate containers). I am using ecs-cli to achieve this atm.
The problem is that in ECS the webservice IPs don't get resolved via docker-compose service name. So how do I let my services know about each others IP addresses or domain names? What environment variable values should be defined in the docker-compose file? What are the common ways to solve this issue? What is the best way to solve this?
I use AWS ECR as docker image repo. My docker-compose file looks like this:
version: "3.7"
services:
service1:
image: myAwsAccount.dkr.ecr.eu-middle-42.amazonaws.com/service1:staging
container_name: service1-composed
ports:
- 4001:4001
environment:
- ExtractUrl=http://service3:2001/api
- ReportingUrl=http://service1:4001/api/reporting
- RestorationUrl=http://service2:3000/api
- CORE_URL=http://0.0.0.0:4001
service2:
image: myAwsAccount.dkr.ecr.eu-middle-42.amazonaws.com/service2:staging
container_name: service2-composed
environment:
- COORDINATOR_URL=http://service1:4001/api/coordinator
service3:
image: myAwsAccount.dkr.ecr.eu-middle-42.amazonaws.com/service3:staging
container_name: service3-composed
environment:
- COORDINATOR_URL=http://service1:4001/api/coordinator
- CORE_URL=http://service1:4001/api/core
As per https://aws.amazon.com/blogs/compute/task-networking-in-aws-fargate/ default network mode for aws fargate tasks is awsvpc, which has default network loopback interface, meaning you can make internal http calls to well known address http://127.0.0.1: