I’ve spent a lot of time playing with Docker containers locally for various personal projects, but haven’t spent much time deploying them to the cloud. I did look at IBM Bluemix a while back, and their web console and toolset was a pretty good developer experience. I’m curious about how OpenShift Online is evolving into a container based service, as I’ve deployed many personal projects to OpenShift, and it has to be my favorite PaaS for features, ease of use, and cost.
AWS is the obvious leader in this space, and despite playing with a few EC2 services during the developer free year, I hadn’t tried yet to deploy Docker containers there.
AWS’s Docker support is EC2 Container Service, or ECS.
Create an AWS user in AWS IAM for authenticating between your local Docker install and with ECS (this user is used instead of your master Amazon account credentials).
Run ‘aws configure’ locally and add secret key credentials from when you created your admin user in IAM
Follow through the step in the ECS Getting Stared guide here.
To summarize the steps in the getting started guide:
- From the ECS Control Panel, create a Docker Image Repository.
- Connect your local Docker client with your Docker credentials in ECS:
aws ecr get-login --region us-east-1
- Copy and paste the Docker login command from the previous step. This will log you in for 24 hours
- Tag your image locally ready to push to your ECS repository – use the repo URI from the first step:
docker tag imageid ecs-repo-uri
The example command in the docs looks like this:
docker tag e9ae3c220b23 aws_account_id.dkr.ecr.region.amazonaws.com/repository-name
For the last param, the tag name, use the ECS Docker Repo URI when you created the repo.
Push the image to your ECS repo with (where image-tag-name is the same as the tag name above):
docker push image-tag-name
Docker images are run on ECS using a task config. You can create tasks with the web UI, or manually as a JSON file. If you create them from the web UI, you can copy the JSON from the configured task as a template for another task.
Before you can run a task, you need to create a cluster, using the web UI.
Run your task specifying the EC2 cluster to run on:
aws ecs run-task –task-definition task-def-name –cluster cluster-name
If you omit the –cluster param, you’ll see this error:
Error: "An error occurred (ClusterNotFoundException) when calling the RunTask operation: Cluster not found."
To check cluster status:
aws ecs describe-clusters –cluster cluster-name
Ensure you have an inbound rule on your EC2 security to allow incoming requests to the exposed port on your container (e.g. TCP 80 for incoming web traffic).
Next up: Deploying a single container is not particularly useful. So next, I’m going to take a look at adding Netflix Eureka for the discovery of other deployed services in containers.