Vic
Vic

Reputation: 645

can't map ec2 instance port to docker container's port

I use ECS to deploy a docker container to ec2 instance.

My ECS task definition:

{
  "containerDefinitions": [
    {
      "name": "postgraphile-container",
      "image": "019384571013.dkr.ecr.us-east-2.amazonaws.com/test-repository",
      "memory": 500,
      "essential": true,
      "portMappings": [
        {
          "hostPort": 5000,
          "containerPort": 5000,
          "protocol": "tcp"
        }
      ]
    }
  ],
  "volumes": [],
  "memory": "900",
  "cpu": "128",
  "placementConstraints": [],
  "family": "postgraphile",
  "taskRoleArn": ""
}

When I ssh into my ec2 instance, I do see the container running. When I attach to running container, I can see that my node app is running on port 5000, I successfully get a response with curl localhost:5000. When I exit from the container and try to do the same in the ec2 instance, I get an error: curl: (56) Recv failure: Connection reset by peer.

I also got a docker container ip with docker inspect and tried to do the same curl <container ip>:5000 and got this error: curl: (7) Failed to connect to 172.17.0.2 port 5000: Connection refused

Am I missing anything? Still can't access the service running inside the container

Upvotes: 2

Views: 1836

Answers (1)

Vic
Vic

Reputation: 645

I figured out the reason: my nodejs app inside the container was listening the connections from localhost by default. I configured it to accept requests from any source, and everything worked fine with the above config.

Upvotes: 4

Related Questions