title: ECS+NLB does not support dynamic port hence only 1 task per EC2 instance?
body: <p>Please confirm if these are true, or please point to the official AWS documentations that describes how to use dynamic port mapping with NLB and run multiple same tasks in an ECS ES2 instance. I am not using Fargate.</p>
  
  <ol>
  <li>ECS+NLB does NOT support dynamic port mapping, hence</li>
  <li>ECS+NLB can only allow 1 task (docker container) per EC2 instance in an ECS service</li>
  </ol>
  
  <p>This is because:</p>
  
  <p><a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/create-load-balancer.html" rel="nofollow noreferrer">AWS ECS Developer Guide - Creating a Load Balancer</a> only mentions ALB that can use dynamic port, and not mention on NLB.</p>
  
  <blockquote>
    <p>Application Load Balancers offer several features that make them attractive for use with Amazon ECS services:<br/><br/>
    * Application Load Balancers <strong>allow containers to use dynamic host port mapping</strong> (so that multiple tasks from the same service are allowed per container instance).</p>
  </blockquote>
  
  <p>ECS task creation page clearly states that dynamic port is for ALB.</p>
  
  <p><a href="https://i.stack.imgur.com/BJPY6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BJPY6.png" alt="enter image description here"></a></p>
  
  <p><a href="https://forums.aws.amazon.com/message.jspa?messageID=805080" rel="nofollow noreferrer">Network Load Balancer for inter-service communication</a> quotes a response from the AWS support:</p>
  
  <blockquote>
    <p>"However, I would like to point out that there is currently an ongoing issue with the NLB functionality with ECS, mostly seen with dynamic port mapping where the container is not able to stabilize due to health check errors, I believe the error you're seeing is related to that issue. I can only recommend that you use the ALB for now, as the NLB is still quite new so it's not fully compatible with ECS yet."</p>
  </blockquote>
  
  <hr>
  
  <h1>Updates</h1>
  
  <p>Found a document stating NLB supports dynamic port. However, if I switch ALB to NLB, ECS service does not work. When I log into an EC2 instance, an ECS agent is running but no docker container is running. </p>
  
  <p>If someone managed to make ECS(EC2 type)+NLB work, please provide the step by step how it has been done.</p>
  
  <ul>
  <li><a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/load-balancer-types.html#nlb" rel="nofollow noreferrer">Amazon ECS Developer Guide - Service Load Balancing - Load Balancer Types - NLB</a></li>
  </ul>
  
  <blockquote>
    <p>Network Load Balancers support dynamic host port mapping. For example, if your task's container definition specifies port 80 for an NGINX container port, and port 0 for the host port, then the host port is dynamically chosen from the ephemeral port range of the container instance (such as 32768 to 61000 on the latest Amazon ECS-optimized AMI). When the task is launched, the NGINX container is registered with the Network Load Balancer as an instance ID and port combination, and traffic is distributed to the instance ID and port corresponding to that container. This dynamic mapping allows you to have multiple tasks from a single service on the same container instance. </p>
  </blockquote>