Finally, I can understand why we got this errors
service sample-webapp-service was unable to place a task because no container instance met all of its requirements. The closest matching container-instance XXXXX e is already using a port required by your task. For more information, see the Troubleshooting section.
Actually, it because of the strategy of the settings “Minimum healthy percentage” and “Maximum healthy percentage”.
In my situation, I had 1 cluster contains 2 instances, “Desired count” is 2, “Minimum healthy percent” is 50%, “Maximum healthy percentage” is 200%, “Container Port Mappings” is 80:3000.
Once I update the service with the new task definition, now the “healthy percentage” is 100%, it doesn’t achieve 200%, so the service won’t stop the running task (container), conversely it will run another container in on of the 2 instances. But there had been a container existing used the port 80 in this instance, so definitely we will get the error above.
So I downgrade the value of “Maximum healthy percentage” to 100%, then I did the same operation, the service will stop 1 task and start a new one, then stop another old running task, start another new one.
Additionally, if you use “Load Balancing” for service, we should pay attention to the attribute “Deregistration delay” of a target group, because it will decide after how many time a task (container) will be stopped.