I'm trying to set up ECS with dynamic port mapping, Application Load Balancer and Auto Scaling Group. It was all working fine, until I changed hostPort in the task definition to 0.
Now in the target groups, targets are being registered with the container port, for example 80 or 8080 instead of dynamically allocated port and because of that health checks are failing since the application does not work on this host port. After that, target with correct port is registered, but since the other targets'(with the same instance ID) health checks failed, the instance goes into draining state.
For now, I've changed health check type to EC2, I still have two registered targets, one unhealthy with container port and one healthy with dynamically allocated port, but the instance is running.
I have all ports opened in my EC2 security group, I'm using default network mode(which in this case is bridge) and I have traffic port as my setting in the target group. I'm also using spot instances in my ASG but I don't think that should make any difference. What can be the problem here?
Thank you for your help!