DEV Community

Cover image for Day 38: Deploying Containerized Applications with Amazon ECS
Thu Kha Kyawe
Thu Kha Kyawe

Posted on

Day 38: Deploying Containerized Applications with Amazon ECS

Lab Information

The Nautilus DevOps team is tasked with deploying a containerized application using Amazon's container services. They need to create a private Amazon Elastic Container Registry (ECR) to store their Docker images and use Amazon Elastic Container Service (ECS) to deploy the application. The process involves building a Docker image from a given Dockerfile, pushing it to the ECR, and then setting up an ECS cluster to run the application.

Create a Private ECR Repository:

Create a private ECR repository named devops-ecr to store Docker images.
Build and Push Docker Image:

Use the Dockerfile located at /root/pyapp on the aws-client host.
Build a Docker image using this Dockerfile.
Tag the image with latest tag.
Push the Docker image to the devops-ecr repository.
Create and Configure ECS cluster:

Create an ECS cluster named devops-cluster using the Fargate launch type.
Create an ECS Task Definition:

Define a task named devops-taskdefinition using the Docker image from the devops-ecr ECR repository.
Specify necessary CPU and memory resources.
Deploy the Application Using ECS Service:

Create a service named devops-service on the devops-cluster to run the task.
Ensure the service runs at least one task.

Lab Solutions

Step 1: Create a Private ECR Repository

Log in to the AWS Management Console

Navigate to Elastic Container Registry (ECR)

Click Create repository

Repository Settings

Visibility: Private

Repository name:

devops-ecr

Leave all other options as default

Click Create

Copy the repository URI (you will need it later), for example:

xxxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/devops-ecr

Step 2: Build Docker Image on aws-client

Log in to the aws-client host.

Go to the Dockerfile directory:

cd /root/pyapp
# Build the Docker image:
docker build -t xxxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/devops-ecr .
# Verify the image:
docker images
Enter fullscreen mode Exit fullscreen mode

Step 3: Authenticate Docker to ECR

Authenticate Docker with ECR:

aws ecr get-login-password --region us-east-1 \
| docker login --username AWS --password-stdin xxxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/devops-ecr
Enter fullscreen mode Exit fullscreen mode

✅ Login should succeed without errors.

Step 4: Push Docker Image to ECR

Push the image:

docker push xxxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/devops-ecr
Enter fullscreen mode Exit fullscreen mode

Verify in ECR → devops-ecr → Images

You should see the latest tag

Step 5: Create ECS Cluster (Fargate)

Go to ECS → Clusters

Click Create cluster

Cluster Configuration

Cluster name:

devops-cluster

Infrastructure: AWS Fargate

Click Create

Step 6: Create ECS Task Definition

Go to ECS → Task definitions

Click Create new task definition

Select Fargate

Click Next

Task Definition Settings

Task definition name:

devops-taskdefinition

Task role: None

Operating system: Linux

CPU: 256 (.25 vCPU)

Memory: 512 MiB

Container Configuration

Configure:

Container name: devops-container

Image URI:

xxxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/devops-ecr:latest

Port mappings:

Container port: 80

Click Create

Step 7: Create ECS Service

Go to ECS → Clusters → devops-cluster

Click Create service

Service Configuration

Launch type: Fargate

Task definition: devops-taskdefinition

Service name:

devops-service

Deployment configuration

Desired tasks: 1

Networking

VPC: Default

Subnets: Select at least one

Security group: Allow required container port (e.g., 80)

Auto-assign public IP: ENABLED

Click Create service

Step 8: Verify Deployment

Go to ECS → Clusters → devops-cluster → Services

Select devops-service

Confirm:

Running tasks: 1
Status: ACTIVE

Open the Tasks tab and ensure task state is RUNNING and check public ip

Expect Output from Web

Welcome to KKE AWS cloud labs!


Resources & Next Steps
📦 Full Code Repository: KodeKloud Learning Labs
📖 More Deep Dives: Whispering Cloud Insights - Read other technical articles
💬 Join Discussion: DEV Community - Share your thoughts and questions
💼 Let's Connect: LinkedIn - I'd love to connect with you

Credits
• All labs are from: KodeKloud
• I sincerely appreciate your provision of these valuable resources.

Top comments (0)