Best practise: migrating multiple VMs and VHosts to Docker

Solution 1:

We typically use ECS (Elastic Container Service) with an X number of tasks (= your websites) and Y number of hosts (= EC2 instances for running those tasks), where X >= Y. Then we let ECS distribute the tasks across the hosts as it sees fit according to the requirements. You can specify the amount of RAM and CPU power each task/website needs.

We also have the EC2 instances in an Auto-Scaling Group - if one of them dies it's automatically replaced and ECS then automatically re-deploys the lost containers and registers them to the Load Balancers, all without any human intervention.

You may also want to run some tasks in AWS Fargate, which is a serverless container service - especially for the larger tasks/websites it may be a good option. For tiny tasks it's often more economical to consolidate them on a single EC2 instance.

The bottom line is to decouple the tasks (containers) from the hosts - have a pool of websites and don't care where they run, and have a pool of hosts and don't care what runs on them. It needs some level of automation though - you want the tasks automatically registered to ALB Target Groups, hosts automatically added when running out of capacity / replaced if they die, etc. But this basic automation should be a given anyway.

Hope that helps :)