39
votes

I try to setup a little example on AWS Fargate and try to have one application container with one database container there.

The task definition starts both containers, but my app container fails with getaddrinfo ENOTFOUND db db:3306. Therefore, the database container could not be found by my app container.

Since Fargate does not allow "links" of Docker containers, i'd like to know how they can communicate with each other. The database container has the name db with port 3306 and my app container is configured to use this.

Unfortunately, defining links of containers is not available for Fargate, but only for "oldschool" ECS/EC2.

In a local docker-compose setup it is working this way.

2
But what was the change that you did to resolve your issue? Based on the answer you accepted, nothing is required for you to change.OK999
In my deployed app, I tried to reference the DB as "db:3306". When I deploy the app and db, and reference the db with "localhost:3306" (instead of the service name) it works.sebastian

2 Answers

59
votes

Containers in Fargate tasks share a network namespace, so you don't need to use links at all. You can simply communicate via localhost.

For example, if you have container A running a web server on port 8000, container B could reach it with curl http://localhost:8000/

-3
votes

You can probably set it up so the services can communicate over the public IP address with each other, then secure the ports using a VPC only the services can communicate with themselves on.