Hot

6/recent/ticker-posts

How to deploy a Docker Container on AWS Elastic Container Service (ECS) using Elastic Container Registry (ECR)

Developing applications, models, and software from scratch is another thing, but what good does it make if you can’t deploy it for the end-users to access?


 Exactly!

In this article, I’ll guide you on how to deploy a docker container on ECS using ECR. (Don’t worry you’ll be more familiarize with these short terms in few minutes)



This is my simple drawing of what I’m about to do.

Overview of Amazon ECS and Amazon ECR

Amazon ECS is a highly scalable, fast container management service that makes it easy to run and manage Docker containers on a cluster of Amazon EC2 instances and eliminates the need to operate your own cluster management or worry about scaling management infrastructure.

In order to reliably store Docker images on AWS, ECR provides a managed Docker registry service that is secure, scalable, and reliable. ECR is a private Docker repository with resource-based permissions using IAM so that users or EC2 instances can access repositories and images through the Docker CLI to push, pull, and manage images.

If you want to read more about ECS and ECR, Click here.

This article is consists of 4 major parts.

  1. Creating a Repository on ECR (To push our docker image to ECR Cloud)
  2. Dockerize the Python Application (Basic containerization but carefully read and understand each step of it)
  3. Push it on ECR (Elastic Cloud Registry) Container
  4. Deploy that container on an ECS (Elastic Container Service) node

Before moving on with my article, I assume that you have a basic knowledge about AWS and hope you guys have settled inn for a account so you can create a new tab and follow me on with each step.

 

1. Create a Repository on ECR (Elastic Container Registry)

What is Amazon ECR?

Amazon Elastic Container Registry (ECR) is a fully-managed Docker container registry that makes it easy for developers to store, manage, and deploy Docker container images. Amazon ECR is integrated with Amazon Elastic Container Service (ECS), simplifying your development to production workflow. Amazon ECR eliminates the need to operate your own container repositories or worry about scaling the underlying infrastructure. Amazon ECR hosts your images in a highly available and scalable architecture, allowing you to reliably deploy containers for your applications. Integration with AWS Identity and Access Management (IAM) provides resource-level control of each repository. With Amazon ECR, there are no upfront fees or commitments. You pay only for the amount of data you store in your repositories and data transferred to the Internet.

How do I create a Repository in ECR?

  1. Install the AWS CLI — You can use the AWS command line tools to issue commands at your system’s command line to perform Amazon ECS and AWS tasks. This can be faster and more convenient than using the console. The command line tools are also useful for building scripts that perform AWS tasks.

To use the AWS CLI with Amazon ECR, install the latest AWS CLI version (Amazon ECR functionality is available in the AWS CLI starting with version 1.9.15). You can check your AWS CLI version with the aws — version command.

For information about installing the AWS CLI or upgrading it to the latest version, see Installing the AWS Command Line Interface in the AWS Command Line Interface User Guide.

2. Open Powershell/Terminal

Type the following command to create a new repository called python-app-aws.

aws ecr create-repository --repository-name python-app-aws

Go to AWS Console and search for ECR in services.

And click on Repositories so you can see your repository has been created.

2. Dockerize the Python Application

Go to the following link to clone/download this python app that I’m going to dockerize. (Please ignore the DP :) )

As per my repository, You are going to need 3 files.

  1. app.py
  2. Dockerfile
  3. requirements.txt

Once you have finished setting up the above files, Let’s try to build this folder in docker as the very first step for containerization.

Read more about Docker and how it’s been used in this awesome tutorial.

3. Push it on ECR (Elastic Cloud Registry) Container

** Ensure you have installed the latest version of the AWS CLI and Docker. For more information, see the ECR documentation.

  • Open Powershell in Windows/ Terminal in Mac to do the ABTP!
  • A- Authenticate
  • B- Build
  • T- Tag
  • P- Push
  1. Retrieve the login command to use to authenticate your Docker client to your registry. Use AWS Tools for PowerShell:
Invoke-Expression -Command (Get-ECRLoginCommand -Region ap-southeast-2).Command

2. 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 python-app-aws .

3. After the build completes, tag your image so you can push the image to this repository: *Make sure to replace the name ID from your unique URL for the repository you have created*

docker tag python-app-aws:latest ID.dkr.ecr.ap-southeast-2.amazonaws.com/python-app-aws:latest

4. Run the following command to push this image to your newly created AWS repository:

docker push ID.dkr.ecr.ap-southeast-2.amazonaws.com/python-app-aws:latest

The word after colon (:) is the tag part so you can identify each version of pushes. For example; I’ve pushed two images called :latest and :v2

Image tag has two attributes since I’ve pushed the image two times now.

4. Deploy that container on an ECS (Elastic Container Service) node

I. Create a Task Definition.

Before you can run Docker containers on Amazon ECS, you must create a task definition. You can define multiple containers and data volumes in a task definition. For more information about the parameters available in a task definition, see Task Definition Parameters.

To create a new task definition

  1. Open the Amazon ECS console at https://console.aws.amazon.com/ecs/.
  2. In the navigation pane, choose Task Definitions, Create new Task Definition.
  3. On the Select compatibilities page, select the launch type that your task should use and choose the Next step.
  4. Select Fargate launch type.
  • The Fargate launch type is not compatible with Windows containers.

5. Follow these steps under the Fargate tab.

  • Important: In the containerDefinitions section of your task definition, specify the ECR image aws_account_id.dkr.ecr.region.amazonaws.com/repository:tag as the image property. (Click on below link for further information)


After you created the Task Definition, it should look like this on the dashboard. (I’ll highlight the important fields in Yellow color in case you missed those essential efforts in the documentation links I’ve posted above; You can double-check and guarantee that you are on the correct path as I am.)

Make sure to add the IAM role ecsTaskExecutionRole as Task Execution Role
Ensure that the container is attached to your task def. (Under image name; ECR URL should be displayed)

II. Create a Service to run the above task definition.

All services require some basic configuration parameters that define the service, such as the task definition to use [Which we want exactly], which cluster the service should run on, how many tasks should be placed for the service, and so on. This is called the service definition. For more information about the parameters defined in a service definition, see Service Definition Parameters.

This procedure covers creating a service with the basic service definition parameters that are required. After you have configured these parameters, you can create your service or move on to the procedures for optional service definition configuration, such as configuring your service to use a load balancer.

Click on this link and follow the steps to create a service for Fargate Launch type. (Create 3 replica task)

After you created the Service, it should look like this on the dashboard. (I’ll highlight the important fields in Yellow color in case you missed those essential efforts in the documentation links I’ve posted above; You can double-check and guarantee that you are on the correct path as I am.)

Target Group name is Highlighted
Note and understand the Service Type, Launch Type, Service Role.


Select Target Group which leads you to here.

Click on Load Balancers to checkout our load balancer and select the Load Balancer

Copy the DNS name and paste it on a new browser window and Voila!

Python app Hosted on ECS
  • Try to refresh the window several times and see how the Hostname getting changed and you can see three different hostnames which is according to the number of Replica tasks we have established in our service.

Thank you very much for your time on reading this post, This can be seriously difficult to understand in one read because trust me I had to spend days to gather all these information (We are data scientists, not DevOps engineers) before I successfully deployed this simple app on ECS so just be patient and progress by step by step. If you run into any errors, Let me know.


Keen on getting to know me and my work? Click here for more!

Post a Comment

SNS TechAugust 24, 2021 at 11:59 PM

thank you

Delete
Dilan JayasekaraAugust 27, 2021 at 11:33 PM

You're most welcome!

Delete

fun town rv winstar - aogiadinh123 sbobet ทางเข้า sbobet ทางเข้า 11bet 11bet 메리트카지노 메리트카지노 186NFL Football Lines Week 2 Best Bets for Tonight - Casinoland

Delete

相关内容推荐

哈根达斯月饼价格网球计分规则连维良简历韩妆品牌魔法少女奈叶as征婚广告安图天气如果我是梁山伯5寸照片多大江苏教师管理网女警察被绑架金素贤电信卡怎么查流量accepting诤友是什么意思泰国电视剧国语版马佳佳网店零存整取计算器三点水加金李辅仁投入产出比怎么算春晚导演aslongas武汉长江大桥有多长扶老携幼的意思曲阜市地图龌龊怎么读汤玉麟金鱼的记忆世界旅游组织秦五爷李宇辰红玫瑰葡萄樱桃小丸子真人版穿越言情小说cameltoe三无产品是指overall黑化saber6磅是多少斤文登地图海信邮箱acgzone十戒蓝天之约酒托是什么意思正者无敌大结局韵母是什么深圳东站在哪里美国德克萨斯州时间想念的英文民国恩仇录裸钻价格查询零存整取计算器永巷黑瞎子岛在哪里个旧三中李霄云刘惜君熔鳞鲶鱼阴谋的代价determiner天下3怎么样bothering熊音曲线行驶技巧cf空白名字复制金苹果减肥怎么样beach是什么意思汽车之家双11购车节曹雪芹简介霸气侧漏什么意思砭怎么读谢谢你给我的温柔十五的月亮歌谱绿度母心咒不三不四审时度势的拼音竞价长春到白城火车时刻表哈尔滨到北京的火车贺州市地图扎西卓玛奔驰600报价obvious是什么意思好运来歌曲下载大侦探怪兽之谜纪家盈安息角乘号符号三和人才市场惠普官网首页滴答吉他谱后桥速比网银专业版000727股吧以讹传讹的意思寻常的反义词竖中指什么意思护肤品团购网strong的反义词bin文件是什么吉普赛回旋曲珊瑚海吉他谱miss什么意思什么是量词梧州市地图雪之华罗马音卢馆金奎丽10001网上营业厅躲进小楼成一统秘鲁结画蛇添足是什么意思原来如此英语蓬灰水霍启刚身高陕西国防职业技术学院刺身是什么巢湖美食卫辉天气八连杀苏三伞兵打一成语尚湖风景区刘雅丽摩尔庄园蘑菇洞王充博览魔法少女奈叶as大明王朝1566演员表苍白的近义词憧憬的意思是什么满目疮痍的意思淘宝资讯skap春节倒计时抄送格式521是什么星座深圳义工联大快刀二十一工重生之静候锦年忽略的反义词懵懂什么意思庞然大物的反义词余德琳石河子市地图无能为力歌词满洲里天气预报佛说简谱后弦娃娃脸下堂王妃要改嫁大漠沙如雪的下一句小石潭write的现在分词海清的老公赵韩樱子的老公沈石溪的作品东城麻美心墙吉他谱疯狂靓妹仔弓长岭水上乐园齐齐哈尔大学图书馆将进酒朗诵配乐乐清市地图刘慈欣乡村教师文职将军眉粉怎么用查无音信兰陵王主题曲吴京个人资料qa虎门外语学校吴忠全turndown唱支山歌给党听歌词vibo鸽子情缘空手道等级白颈鸦河南分数线浪之歌奥特之王动画片思雨电影网12999小学数学网胭脂扣歌词呼叫转移收费吗猕猴桃的英文天堂里有没有车来车往陈威翰企图的近义词7月7日晴丁秋星荒凉的反义词是什么盲目草哪里多悦耳的近义词任雪案件梁子庚黄褐斑是什么样的新疆伊宁市k762grace是什么意思

站外内容推荐
慈喀SEO百科 | 关键词排名营销 | 网站seo优化 | 网站建设制作 | 企业seo优化 | 网站关键词排名 | 网站设计制作 | 优化网站排名 | 金凯德工作室 | seo优化公司 | 天津万源聚 | seo优化营销 | 网站SEO优化 | SEO技术团队 | 网站设计制作 | 网站设计制作 | 网络营销推广 | 个人网站制作 | 百度seo公司 | 网站建设制作 | 网站优化公司