Make sure that you have the latest version of the AWS CLI and Docker installed. For more information, seeGetting Started with Amazon ECR
.
Use the following steps to authenticate and push an image to your repository. For additional registry authentication methods, including the Amazon ECR credential helper, see Registry Authentication.
Retrieve an authentication token and authenticate your Docker client to your registry. Use the AWS CLI:
Note: If you receive an error using the AWS CLI, make sure that you have the latest version of the AWS CLI and Docker installed.
Build your Docker image using the following command. For information on building a Docker file from scratch see the instructions here. You can skip this step if your image is already built:
docker build -t demorepo .
After the build completes, tag your image so you can push the image to this repository:
docker tag demorepo:latest 960767354937.dkr.ecr.ap-northeast-1.amazonaws.com/demorepo:latest
Run the following command to push this image to your newly created AWS repository:
Amazon Elastic Container Service (Amazon ECS) is a highly scalable, fast, container management service that makes it easy to run, stop, and manage your containers. You can host your containers on a serverless infrastructure that is managed by Amazon ECS by launching your services or tasks using the Fargate launch type. For more control, you can host your tasks on a cluster of Amazon EC2 instances that you manage by using the EC2 launch type. For a broad overview on Amazon ECS, seeWhat is Amazon Elastic Container Service?.
Get started with Amazon ECS using the EC2 launch type by registering a task definition, creating a cluster, and creating a service in the Amazon ECS console.
A task definition is like a blueprint for your application. Each time that you launch a task in Amazon ECS, you specify a task definition. The service then knows which Docker image to use for containers, how many containers to use in the task, and the resource allocation for each container. For more information about task definitions, see Amazon ECS task definitions.
The following steps walk you through creating a task definition that will deploy a simple web application.
An Amazon ECS cluster is a logical grouping of tasks, services, and container instances. When creating a cluster using the console, Amazon ECS creates a AWS CloudFormation stack that takes care of the Amazon EC2 instance creation, networking and IAM configuration for you. For more information about clusters, see Amazon ECS clusters.
The following steps walk you through creating a cluster with one Amazon EC2 instance registered to it which will enable us to run a task on it. If a specific field is not mentioned, leave the default value the console uses.
From the navigation bar, select the same Region you used in the previous step.
In the navigation pane, choose Clusters.
On the Clusters page, choose Create Cluster.
On the Select cluster template page, choose EC2 Linux + Networking.
For Cluster name, choose a name for your cluster.
In the Instance configuration section, do the following:
For EC2 instance type, choose either the t2.micro or t3.micro instance type to use for the container instance. Instance types with more CPU and memory resources can handle more tasks, but that is unnecessary for this getting started guide. For more information about the different instance types, see Amazon EC2 Instances.
For Number of instances, type 1. Amazon EC2 instances incur costs while they exist in your AWS resources. For more information, see Amazon EC2 Pricing.
For EC2 Ami Id, use the default value which is the Amazon Linux 2 Amazon ECS-optimized AMI. For more information about the Amazon ECS-optimized AMI, see Amazon ECS-optimized AMIs.
In the Container instance IAM role section, choose Create new role to have Amazon ECS create a new IAM role for your container instances, or choose an existing Amazon ECS container instance (ecsInstanceRole) role that you have already created. For more information, see Amazon ECS Container Instance IAM Role.
Choose Create.
Step 3: Create a Service
An Amazon ECS service enables you to run and maintain a specified number of instances of a task definition simultaneously in an Amazon ECS cluster. If any of your tasks should fail or stop for any reason, the Amazon ECS service scheduler launches another instance of your task definition to replace it in order to maintain the desired number of tasks in the service. For more information on services, see Amazon ECS services.
From the navigation bar, select the same Region you used in the previous step.
In the navigation pane, choose Clusters.
Select the cluster you created step 2.
On the Services tab, choose the service you created in step 3.
On the Service: service-name page, choose the Tasks tab.
Confirm that the task is in a RUNNING state. If it is, select the task to view the task details. If it is not in a RUNNING status, refresh the service details screen until it is.
In the Containers section, expand the container details. In the Network bindings section, for External Link you will see the IPv4 Public IP address to use to access the web application.
Enter the IPv4 Public IP address in your web browser and you should see a webpage that displays the Amazon ECS sample application.
Step 5: Clean Up
When you are finished using an Amazon ECS cluster, you can clean up the resources associated with it to avoid incurring charges for resources that you are not using.
The Amazon ECS resources created in this getting started guide, such as the cluster and service can be cleaned up using the Amazon ECS console.
On the Services tab, select the service you created in step 3 and choose Delete. At the confirmation prompt, enter delete me and then choose Delete.
On the cluster details page, choose Delete cluster. At the confirmation prompt, enter delete me and then choose Delete. Deleting the cluster cleans up the associated resources that were created with the cluster, including the VPC and Amazon EC2 instances.