amazon-ecs-agent icon indicating copy to clipboard operation
amazon-ecs-agent copied to clipboard

Problem with port mapping in containers after rebooting instance

Open ynelin opened this issue 10 years ago • 5 comments

Hello everyone

We have one cluster with 1 instance on AWS ECS based on Amazon Linux AMI

uname -a Linux ip-* 4.1.17-22.30.amzn1.x86_64 #1 SMP Fri Feb 5 23:44:22 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

Amazon ecs agent version:

curl -s 127.0.0.1:51678/v1/metadata | python -mjson.tool
"Version": "Amazon ECS Agent - v1.8.1 (304495b)"

Docker version is 1.9.1

There is one docker image, 47 task definitions, that using this image with different port mapping Everything works fine until we have less then 45 services to run, but when we add another 2 - they wont running

Event message is:

service port_20543 was unable to place a task because no container instance met all of its requirements. The closest matching container-instance bdd3cbda-6f6a-4750-b56f-3d1cb8176ca1 is already using a port required by your task. For more information, see the Troubleshooting section.

But port 20543 is free, checked it with

docker inspect -f '{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $(docker ps --format '{{.Names}}')

and netcat

If we rebooting instance - only 45 started, 2 - not, every time - 2 different containers with different ports There is available CPU and memory.

Logs from agent container for port_20543

2016-03-09T19:17:42Z [INFO] Adding event module="eventhandler" change="ContainerChange: arn:aws:ecs:eu-west-1:558122141955:task/a736c1bf-69fe-43c1-89c3-66fb5ec593b0 port_20543 -> STOPPED, Ports [{20543 20543 0.0.0.0 0}], Known Sent: RUNNING"

016-03-09T19:17:42Z [INFO] Sending container change module="eventhandler" event="ContainerChange: arn:aws:ecs:eu-west-1:558122141955:task/a736c1bf-69fe-43c1-89c3-66fb5ec593b0 port_20543 -> STOPPED, Ports [{20543 20543 0.0.0.0 0}], Known Sent: RUNNING" change="ContainerChange: arn:aws:ecs:eu-west-1:558122141955:task/a736c1bf-69fe-43c1-89c3-66fb5ec593b0 port_20543 -> STOPPED, Ports [{20543 20543 0.0.0.0 0}], Known Sent: RUNNING"

and thats all

If I stop all containers, delete images, reinstall agent, reboot instance - only 45 will work, another 2 - will not (every time two different containers)

ynelin avatar Mar 09 '16 20:03 ynelin

There's a limit of 50 reserved host ports per container instance at any given time. By default, 4 ports are reserved already (22 for SSH, the Docker ports 2375 and 2376, and the Amazon ECS container agent port 51678) and 46 remain for assignment with placed tasks. There's a bit more detail in our documentation.

It looks like you're seeing only 45 available right now; we have identified an issue where the limit of 50 is being treated as 49 and are working on a fix.

Note that non-reserved (dynamic) host ports are not limited.

Please let us know if you have any further questions.

Sam

samuelkarp avatar Mar 09 '16 20:03 samuelkarp

Can I increase this limit? Why it there? I have resources on my instance to run a lot more containers. I need to know port before running container because external hardware is setting up for using this port.

ynelin avatar Mar 09 '16 20:03 ynelin

@ynelin The process for requesting limit increases is here, and we can discuss your particular use-case through that process.

samuelkarp avatar Mar 09 '16 21:03 samuelkarp

@samuelkarp , thanks. I created ticket for support. One more thing. In ticket system for ECS increase limits there is no paragraph for user specified ports. Maybe it should be there...

ynelin avatar Mar 10 '16 14:03 ynelin

@ynelin Thank you for creating the limit increase request. I'll resolve this issue now.

samuelkarp avatar Mar 11 '16 19:03 samuelkarp