title: I can't deploy a new container to my ECS cluster because of ports in use
body: <p>The task definition my Service uses is pulling the "latest" tagged version of my image.</p>
  
  <p>When I update my service though and "force new deployment" i look at the events and see this:</p>
  
  <pre><code>service MYSERVICE was unable to place a task because no container instance met all of its requirements. The closest matching container-instance .... is already using a port required by your task
  </code></pre>
  
  <p>I then went to my cluster and stopped all tasks.</p>
  
  <p>Then went back to my Service and updated with force new deploy again. This seems to have worked</p>
  
  <p>Will I have to stop all tasks and update the service each time I want to deploy a new image? Or is there a "right" way to do this?</p>
  
  <h2>EDIT: So if I stop one task the service will automatically replace it. So I can update my service and "force new deploy" then stop one task at a time to get a sort of a rolling update. Not sure if there is a feature to automate that beyond my own scripting</h2>
  
  <p>Just to follow up, as stated in the answers I just needed to use dynamic port mapping.</p>
  
  <p>Initially, when I first started I didn't have a load balancer so I was hitting the EC2 instances directly to access the running containers. Of course in order to do this I had to expose a static port on the EC2 host.</p>
  
  <p>I added a load balancer but kept that static port mapping not understanding how dynamic port mapping worked. All I had to do was change my task definition to set the host port to "0". Now I have no static port mappings on the hosts, the NLB does the routing for me and deploys work as expected</p>