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:latest hostname: "mongodb" national-parks: image: aws_account_id.dkr.ecr.ap-southeast-2.amazonaws.com/username/national-parks:latest ports: - "8080:8080" links: - mongo command: --peer mongodb --bind database:mongodb.default
From the example, the
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
command entry for the National Parks Tomcat application allows the Chef Habitat Supervisor to
--peer to the
mongo gossip ring and
database entries to its Mongo configuration.