What is ECS?
Elastic Container Service is Amazon platform for Docker containers. A cluster is a collection of ECS container instances, which in turn are EC2 instances running the Docker Engine along with an ECS agent that provides AWS resources for running containers. This article will describe the steps needed to make use of this service.
Create a cluster
Containers in AWS are always located in a cluster.
- Start by logging on with your IAM account, and assume the role of admin.
- Go to Services > Elastic Container Service.
- If this is your first visit, click the Get started button, and then click Cancel to get back to the ECS console.
- Click the Create cluster button.
- Select EC2 Linux + Networking.
- On the Configure cluster page enter the following details:
- Cluster name: test-cluster
- Provisioning Model: On-Demand Instance
- EC2 instance type: t2.micro (free for first 12 months)
- Number of instances: 1
- EC2 Ami Id: Amazon Linux 2 AMI
- EBS storage (GiB): 22
- Key pair: admin (create a key pair called admin if you haven't already)
- Leave rest at default, and click the Create button.
This will set up a cluster with one EC2 instance, for Docker with Linux, with internet access on port 80. Click View Cluster once the creation is complete.
SSH access to your EC2 instance
There may be times when you need to access your ECS instance using SSH.
- Go to Services > EC2.
- Select Security Groups (left pane).
- Select your security group (e.g. EC2ContainerService-test-cluster-EcsSecurityGroup-xxxx.)
- Select the Inbound rules tab.
- Click the Edit inbound rules button.
- Click the Add rule button and add the following settings:
- Type: Custom TCP
- Port range: 22
- Source type: My IP
- Description: SSH access.
- Click Save rules.
SSH access is now enabled.
IP address of EC2 instance
Your EC2 instance has an IP address that you will need.
- Go to Services > EC2.
- Select Instances (left pane).
- Select your EC2 instance.
You can see its IP address if you scroll right, or look at the details pane below.
Using this IP addresss, you can open a Terminal and run the following command (create an EC2 key pair called admin, if you haven't already):
Now that you have remote access to your ECS instance, you can run the following command to list docker containers, and you will see the ECS agent, running as a container.
$ docker ps
At this stage you have enough to start using Docker on AWS.
Thanks for visiting.