I am running 8 docker containers. When I am running the containers, my ec2 instance becomes very slow, sometimes stops responding. When I stop the containers it is working fine.
When I run docker-compose down it gives me timeout.
Your post does not mention the instance type (cpu/ram), nor how many resources the container require at peak, nor how much load is on the system. We also don’t know the deployed containers use cpu/memory request/limit or not.
For all we know the system could be drowning from load because of overpromising.
The instance size is way to small for decent operation. With two cpu’s the load should not be more than 2 for your system to catch up with it.
If you put into account the OS runs services that require memory as well, your system could be constantly busy with swapping, especially if the peak resource usage is beyond what the point in time snapshot shows.
I am not surprised the system is slow. Try a bigger instance size. You can shut down the instance, change the size and restart it again, there is no need to delete the instance.
It’s up to you to find the sweet spot between required instance size and pricing.