Warakorn - Fotolia

How can we save money in Amazon EC2 Container Service?

Our group doesn't need containers all the time. How can we scale back or stop a Docker container that's running in Amazon Elastic Container Service?

Container-based virtualization eliminates the need for separate operating systems in each VM -- saving money on licensing costs, boosting performance and improving efficiency. Amazon EC2 Container Service offers hosted, managed and fully programmable APIs to run Docker containers from within EC2. But cloud administrators must manage cloud deployments to reduce or eliminate unused resources.

Each time a VM or container is provisioned to a cloud service such as Amazon EC2 Container Service (ECS), the associated computing resources incur costs. And as long as those resources are allocated to the instance, those costs recur monthly. And while it's easy to set up and use an Amazon ECS cluster to experiment or test applications, it's vital to clean up those resources when you're done -- or pay the price.

There are three ways to free up resources in Amazon ECS: scaling, deregistering and deleting. To start, scale down inactive services; this reduces or eliminates tasks associated with an unnecessary service. By preventing Amazon ECS from starting unnecessary or unproductive new tasks for that service, admins can free up resources for other operations.

Next, deregister unneeded container instances to stop any tasks that are running on the deregistered container. This also prevents the container from starting new tasks. If you plan to eventually delete a cluster, you'll need to deregister all of the container instances inside that cluster. While deregistering removes the container from your cluster, administrators must explicitly terminate the instance to cease billing.

Administrators also can delete services, clusters and even the AWS CloudFormation stack as needed to reduce billing costs and unneeded resources. For example, administrators can delete services within a cluster. Once there are no longer any tasks running in the service, administrators can use the Amazon ECS console to remove the service and free resources.

After the active services within a cluster have been scaled down and deleted, admins can delete the cluster. The ultimate cleanup process is to delete the AWS CloudFormation stack, which then deletes EC2 instances, removes Auto Scaling, deletes any virtual private cloud subnet or Internet gateway allocated to the cluster, and removes any elastic load balancing implementation.

Administrators can perform these operations through the Amazon ECS Management Console or the AWS command-line interface using structured command. Advanced resources, such as EC2 instance management, load balancing and Auto Scaling group management, must be handled through the EC2 Management Console or by deleting the associated AWS CloudFormation stack through the AWS CloudFormation console.

Next Steps

Benefits of using Amazon EC2 Container Service with Docker

Deploy server clusters with AWS EC2 Container Service

Docker on AWS: It's not you, it's me

Learn how Amazon ECS helps organizations run containers

Dig Deeper on AWS infrastructure