Deploy Docker Container On AWS ECS !

Step by Step guide for DevOps Engineer friends

Saqib Ullah Siddiqui
4 min readJul 16, 2022

In this blog post, we will see how to deploy a docker container on AWS ECS platform, as usual, this blog is more focused on a particular guide rather than theory. To get a core understanding of ECS and ECR read amazon web service official documentation.

Let’s jump and login into the AWS console.

Create New Policy!

To avoid permissions and policies issues, let’s create a new custom policy first, under IAM > Policies option click Create Policy button. Using Choose a Service option type “Elastic Container Registry” and select it.

First enter Elastic Container Registry and select ECR option

Under Action section select “All Elastic Container Registry actions” checkbox.

Set Policy Action option “All Elastic Container Registry actions (ecr.*)”

Under Resources section select Specific option and click on the Add ARN option.

Select Policy Resources

Create ARN (Amazon Resource Name) by filling all fields as per your requirements.

Create Policy Resource ARN option

It’s optional to add some tags to your new policy, in the last step give some proper name to your policy like “custom_ecr_policy”.

Detail view of policy in JSON form.

ECR policy JSON detail

Create New User !

Next we need to create a new user with name of container_testuser using IAM option of aws console. Select the required checkbox Access Key - Programmatic access and Password — AWS Management Console access options under AWS credential type and set the custom password.

Next we need to add required permission using AmazonECS_FullAccess and newly created custom_ecr_policy policy using Attach existing Policies Directly tab.

AmazonECS_FullAccess and custom_ecr_policy permission summary

Up to this moment, we have a user account with required permission set perfect. !

Create ECR Registry

Now create ECR registry using aws console, in this scenario we created a private repository with the name of nodejs-express-server. We have already created a sample project and you found it on my GitHub repo. Clone my sample project any where in your computer or server.

Create ECR Registry

To get a complete detail instruction and step, select the newly create repository in aws console and click on View Push Command.

ECR Repositories View Push Commands

We have already build our docker image in the last blog please follow this, now we need to Tag the image using following command.

docker tag nodejs-express-server:latest [XXX].dkr.ecr.ap-southeast-1.amazonaws.com/nodejs-express-server:latest

Before pushing image in the ECR repository you need to login using
get-login-password command and once you login you will get Login Succeeded message.

aws ecr get-login-password --region ap-southeast-1 | docker login --username AWS --password-stdin [XXX].dkr.ecr.ap-southeast-1.amazonaws.comLogin Succeeded

Now it’s the time to actually push the docker image AWS ECR area using following

docker push [XXX].dkr.ecr.ap-southeast-1.amazonaws.com/nodejs-express-server:latest

You can verify the image in aws console under.

Docker Image in ECR

Create ECS Part

It’s a service that orchestrate the docker container at a very highly scalable level. ECS is similar to Kubernetes. To start with ECS type “Elastic Container Service” in the AWS console and select it. Click on the “Create Cluster” button and select the “EC2 Linux + Networking” template option and click the Next button. On the next page give the proper name to the cluster like “testing-cluster” and set other options like EC2 instance type “t2.micro” and Key Pair. When you are done click Create button on the right bottom.

EC2 instance type ECS Cluster

In the next few minutes, you will get a new EC2 working instance with a pre-configured network setting. To verify your newly created EC2 instance open the EC2 section in the console.

ECS base EC2 Instance

In this step we are going to create a new ECS Task using aws console option, under Amazon ECS option select Task Definitions and create new Task, next select lunch type compatibility EC2, next give proper task name in our case we set it “newclustertask”.

Create new task

Set task size details !

Set Task size

Click Add Container button and put the basic details like Container Name*, Image* and Port mappings. Once you are done with setting click on Add.

Add Container with port setting

--

--

Saqib Ullah Siddiqui
Saqib Ullah Siddiqui

Written by Saqib Ullah Siddiqui

I read to know, I write to recall.

No responses yet