Scroll Top

Deploying docker image of microservice in Amazon ECS

 Introduction :  

Amazon EC2 Container Service (ECS) supports Docker containers and allows you to easily run applications on a managed cluster of Amazon EC2 instances. It eliminates the need for you to install, operate, and scale your own cluster management infrastructure. With simple API calls, you can launch and stop Docker-enabled applications, query the complete state of your cluster, and access many familiar features like security groups, Elastic Load Balancing, EBS volumes, and IAM roles. Further, you can use Amazon ECS to schedule the placement of containers across your cluster based on your resource needs and availability requirements. You can also integrate your own scheduler or third-party schedulers to meet business or application specific requirements. In nutshell, ECS simplifies Docker container management across EC2 Instances.

 

While it gives significant advantage, it does involves a some understanding of the AWS concepts and some wiring to make things work. In this article, I will explain the steps that you need to follow to deploy the docker image of Microservices in ECS.

Steps for deploying docker containers on ECS

Step1 : Create an ECS cluster which is a group of EC2 instances managed by ECS. Login into Amazon manage console application.     

            

  • Select  EC2 Container Service option from Services dropdown.

              

  • Click on create cluster button and give the name of cluster, the number of EC2 instances, instance type, key pair, networking details. Select container IAM role as ecs Instance Role. If it’s first time, select create new role and click on create.

         

 

 

 

Note : Before creating the ECS cluster, create security group for cluster. Refer the following link for creating security group

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-network-security.html

  • It will create  ECS cluster, IAM Policy and Cloud Formation stack for cluster.

Step 2 : Create a task definition.

Task definition specifies to ECS about which docker image has to run with the following parameters

  • CPU
  • Memory
  • Port
  • Environment variables
  • Linked containers

 

  • Click on Task Definition button and  click on Create New Task button.

  • Provide the task definition name and container details.

  • Click on  Add Container button and provide the data for container name, image name, network ports, number of cpu units.


  • Click on Add button, it will create task definition.

Step 3 : Creating service

 

  • Click on  actions dropdown and select create service option.provide service name,number of tasks and select cluster which we created in step1.          

 

 

 

  • Click on  Create Service button.It will create service and then click on the view service.

  • Click on task link at the bottom of the page.

 

  • Expand the Containers tab and you will find the external link.

  • In order to allow traffic to ec2 instance, you have to configure inbound rule to security group. Select Services  dropdown, select ec2 instances and click on our ec2 instance.  Scroll down, you will find security group link,click on that link.

 

 

 

 

  • Click on edit button and add new rule by clicking Add Rule button. Select type as http and port as 80 (for example) and source as anywhere. Click on the save button.

 

 

 

  • open external link mentioned in step 3. Now you are able to access deployed spring boot microservice application and you will observe following output.

Note

One of the advantages of using ECS is that when you update ECS with a new Service to run a new Task, Amazon automatically begins a blue-green deployment process for you. Depending on the available resources in your auto scaling group, it creates a new EC2 instance with the new Docker image. So all that is needed to deploy a new version of your Docker image is to update the service. To configure how ECS does the blue-green deployment, you can define the minimum and maximum healthy percentages that sets the lower and higher limit of running the tasks during a deployment.

 

Summary

In this article, we explained how to deploy docker image of microservice  to Amazon ECS container service.

Hope this article was informative and leaves you with a better understanding of  deploying docker with microservice in Amazon ECS container service.

At Walking Tree, we strongly believe that the businesses are moving away from the monolithic architecture. Microservices have provided a great alternative. We would love to help you take advantage of this. If you need any professional support, do contact us.  

 

.

 

Related Posts

Leave a comment

Privacy Preferences
When you visit our website, it may store information through your browser from specific services, usually in form of cookies. Here you can change your privacy preferences. Please note that blocking some types of cookies may impact your experience on our website and the services we offer.