HiveBrain v1.2.0
Get Started
← Back to all entries
snippetdockerMinor

How to communicate between AWS ECS containers

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
howecsbetweenawscommunicatecontainers

Problem

Problem

How do ECS containers communicate between each others?
Situation

I use docker compose ecs integration.

In AWS docker context, docker compose up did a deploy correctly.

But reverse proxy doesn't work correctly, maybe because of communication with containers.

My docker-compose.yml

version: '3'
services:
  nginx:
    image: {ACCOUNT}.dkr.ecr.{REGION}.amazonaws.com/{MY_IMAGE}
    ports:
      - "80:80"

  nodeapp:
    image: {ACCOUNT}.dkr.ecr.{REGION}.amazonaws.com/{MY_REACT_IMAGE}
    working_dir: /src
    command: sh -c "yarn install && yarn build && yarn start"
    ports:
      - "3000:3000"


MY nginx.conf

server {
    listen 80;
    server_name localhost;
    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://localhost:3000/;
        # proxy_pass http://nodeapp:3000/; // works only for local
        # proxy_pass http://nodeapp.{MY CLUSTER}.local:3000/; // doesn't work

    }
}


My understandings

  • In the same ECS service, containers can communicate with each other by localhost.



  • In the diffrent ECS service, containers can communicate with each other by service discovery.



Are these correct? And, how do I do that?
1: The same ECS service

I tried to do that at first. But, docker compose up(ecs integration) created different services(for nginx service and application(react) service. How do I configure that?
2: The different service

In nginx conf, proxy_pass http:nodeapp.{MY_CLUSTER}.local:3000 doesn't work correctly.

How do ECS containers communicate between each others?

Let me know the simplest way.

Thanks in advance.

Solution

Understanding 1 is not correct, localhost is only for internal containers not other can access on localhost, if they share same network name can be used, nodeapp:3000 will work on local.

For different services we have to call them by local IP or a domain name if not in same network.

Context

StackExchange DevOps Q#14468, answer score: 2

Revisions (0)

No revisions yet.