AWS ECS awsvpc no communication on localhost

Viewed 702

I am stuck on an issue with containers on ECS Fargate, more specifically 2 containers inside one task communicating with each other.

According the article linked (https://aws.amazon.com/blogs/compute/task-networking-in-aws-fargate/), once the two containers are configured inside the task, any other container in the task should be able to communicate with that container by just using localhost or 127.0.0.1.

However I can’t seem to get that behavior. I tried breaking it down to its simplest form - an nginx running on 1 container with port Mapping 80 and a simple curl command on another container, but no joy.

Am I missing something or some configuration that I need to do to get the 2 containers communicating within the ECS Task Definition over localhost or 127.0.0.1 ?

The JSON file of the Task Definition with 2 containers:

{
"requiresCompatibilities": [
    "FARGATE"
],
"inferenceAccelerators": [],
"containerDefinitions": [
    {
        "name": "container-a",
        "image": "******.dkr.ecr.eu-west-1.amazonaws.com/repository-a:latest",
        "memoryReservation": "2048",
        "cpu": "1024",
        "resourceRequirements": null,
        "essential": true,
        "portMappings": [
            {
                "containerPort": "5000",
                "protocol": "tcp"
            }
        ],
        "environment": null,
        "environmentFiles": [],
        "secrets": null,
        "mountPoints": null,
        "volumesFrom": null,
        "hostname": null,
        "user": null,
        "workingDirectory": null,
        "extraHosts": null,
        "logConfiguration": {
            "logDriver": "awslogs",
            "options": {
                "awslogs-group": "/ecs/test-task-definition",
                "awslogs-region": "eu-west-1",
                "awslogs-stream-prefix": "ecs"
            }
        },
        "ulimits": null,
        "dockerLabels": null,
        "dependsOn": null,
        "repositoryCredentials": {
            "credentialsParameter": ""
        }
    },
    {
        "name": "container-b",
        "image": "******.dkr.ecr.eu-west-1.amazonaws.com/repository-b:latest",
        "memoryReservation": "2048",
        "cpu": "1024",
        "resourceRequirements": null,
        "essential": true,
        "portMappings": [],
        "environment": null,
        "environmentFiles": [],
        "secrets": null,
        "mountPoints": null,
        "volumesFrom": null,
        "hostname": null,
        "user": null,
        "workingDirectory": null,
        "extraHosts": null,
        "logConfiguration": {
            "logDriver": "awslogs",
            "options": {
                "awslogs-group": "/ecs/test-task-definition",
                "awslogs-region": "eu-west-1",
                "awslogs-stream-prefix": "ecs"
            }
        },
        "ulimits": null,
        "dockerLabels": null,
        "dependsOn": null,
        "repositoryCredentials": {
            "credentialsParameter": ""
        }
    }
],
"volumes": [],
"networkMode": "awsvpc",
"memory": "4096",
"cpu": "2048",
"executionRoleArn": "arn:aws:iam::******:role/ecr-execution-role",
"family": "test-task-definition",
"taskRoleArn": "arn:aws:iam::******:role/ecs-task-role",
"tags": []
}
0 Answers
Related