DEV Community

Cover image for Deploy Containerized Applications with ECS
Anuvindh for AWS Community Builders

Posted on

9 4

Deploy Containerized Applications with ECS

DAY 31- Deploy Containerized Applications with ECS - Day Thirty One

Image tweet

100 days of Cloud on GitHub - Read On iCTPro.co.nz - Read on Dev.to


Get the app

Here Iam using a website with nginx server to deploy on a container with the help of ECR.
Let’s get the data

git clone https://github.com/anuvindhs/CLOUD-is-AWSome.git
Enter fullscreen mode Exit fullscreen mode

Docker

Building a docker file

  • Lets build our NGINX docker file for our website.

  • once you have created the docker file inside the folder, copy-paste the below commands

FROM nginx:latest
COPY ./ /usr/share/nginx/html/
Enter fullscreen mode Exit fullscreen mode
  • I am using VScode, check below to understand the folder structure
    Image folder

    AWS Permissions

  • Make sure you have programmatic access via AWS CLI

  • Full permissions to ECS & AmazonEC2ContainerRegistryFullAccess

ECR

Create a repository

  • Goto ECR from AWS console and create a repository
  • Create a ECR repo ,i have named mine webapp-ecr-repo

Login to ECR

if you open the repo, on the right-hand side you can see an option for view push commands.
Image push commands

Now using AWS CLI login to ECR

aws ecr get-login-password --region xx-xxxxxx-xx| docker login --username AWS --password-stdin xxxxxxxxxx.dkr.ecr.xx-xxxxxx-xx.amazonaws.com
Enter fullscreen mode Exit fullscreen mode

Build the docker image

docker build -t webapp-ecr-repo .
Enter fullscreen mode Exit fullscreen mode

Lets tag our image with repo name

docker tag webapp-ecr-repo:latest xxxxxxxxx.dkr.ecr.xx-xxxxxx-xx.amazonaws.com/webapp-ecr-repo:latest
Enter fullscreen mode Exit fullscreen mode

Lets push the image to the repository

docker push xxxxxxxxxx.dkr.ecr.xx-xxxxxxx-xx.amazonaws.com/webapp-ecr-repo:latest
Enter fullscreen mode Exit fullscreen mode

if you are using PowerShell on windows please use windows commands to push the image to the repo.

Image options

ECS

Create a cluster

  • Goto ECS dashboard and click Create Cluster.
  • select EC2 Linux + Networking
    Image ec2

  • Enter Cluster name & EC2 instance type , am keeping it to t2.micro.
    Image clustername

  • Select the default VPC and Subnets available.

  • Also enable Auto assign public IP

Image ip

  • you can use default Security group or create a new one or can attach a Security group which is already created.
  • Now click Create Image create

Creating Task Definition

  • Click on create Task Definition & then select EC2

Image Taskdef

  • I am naming mine as Taskdef-webapp-ecr
  • Update Task memory to 128 and Task CPU to 1 vCPU, then click Add Container
    Image container

  • Add a name, mine is container-webapp-ecr

  • Copy your ECR repo URI from the repository and update that on the image coloumn

  • Map your ports, here its 80:80 ,

  • Now add, and create the Task definition.
    Image task def create

Run the Task

  • goto Clusters, select Task then click Run New task
    Image run a task

  • Select EC2

  • Select out Task Definition we created.

  • Select our Cluster

  • leave everything default and click Run Task
    Image task defined

Once the Task is created you will be able to see a Running Status
if you navigate to external Link you will be able to see the live website.

Image external link

Congratulations, now you have successfully configured a docker image which you have pushed to ECR and Deployed on a container with ECS.


✅Connect with me on Twitter
🤝🏽Connect with me on Linkedin
🧑🏼‍🤝‍🧑🏻 Read more post on dev.to or iCTPro.co.nz
💻 Connect with me on GitHub


Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Best Practices for Running  Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK cover image

Best Practices for Running Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK

This post discusses the process of migrating a growing WordPress eShop business to AWS using AWS CDK for an easily scalable, high availability architecture. The detailed structure encompasses several pillars: Compute, Storage, Database, Cache, CDN, DNS, Security, and Backup.

Read full post