Amazon ECS

[edit on GitHub]

Amazon Web Services provides a container management service called EC2 Container Service (ECS). ECS provides a Docker registry, container hosting and tooling to make deploying Docker-based containers fairly straightforward. ECS will schedule and deploy your Docker containers within a Task while Chef Habitat manages the applications.

EC2 Container Registry

EC2 Container Registry (ECR) is a fully-managed Docker registry provided by Amazon Web Services. Applications exported to Docker with hab pkg export docker put the containers into namespaced repositories, so you will need to create these within ECR. For example, if you were building core/mongodb containers you would use the following command:

$ aws ecr create-repository --repository-name core/mongodb

To tag and push the images to the ECR you will use your Repository URI (substituting your aws_account_id and availability zone).

$ docker tag core/mongodb:latest aws_account_id.dkr.ecr.ap-southeast-2.amazonaws.com/core/mongodb:latest
$ docker push aws_account_id.dkr.ecr.ap-southeast-2.amazonaws.com/core/mongodb:latest

EC2 Compute Service

Once Docker images are pushed to ECR, they may be run on Amazon’s ECS within a Task Definition which may be expressed as a Docker Compose file. Here is an example of a Tomcat application using a Mongo database demonstrating using Chef Habitat-managed containers:

version:'2'services:mongo:image:aws_account_id.dkr.ecr.ap-southeast-2.amazonaws.com/username/mongodb:latesthostname:"mongodb"national-parks:image:aws_account_id.dkr.ecr.ap-southeast-2.amazonaws.com/username/national-parks:latestports:- "8080:8080"links:- mongocommand:--peer mongodb --bind database:mongodb.default

From the example, the mongo and national-parks services use the Docker images from the ECR. The links entry manages the deployment order of the container and according to the Docker Compose documentation links should create /etc/hosts entries. This does not appear to currently work with ECS so we assign the hostname: "mongodb".

The command entry for the National Parks Tomcat application allows the Chef Habitat Supervisor to --peer to the mongo gossip ring and --bind applies database entries to its Mongo configuration.

© Chef Software, Inc.
Licensed under the Creative Commons Attribution 3.0 Unported License.
The Chef™ Mark and Chef Logo are either registered trademarks/service marks or trademarks/servicemarks of Chef, in the United States and other countries and are used with Chef Inc's permission.
We are not affiliated with, endorsed or sponsored by Chef Inc.
https://docs.chef.io/habitat/ecs/