DEV Community

Yash Sonawane
Yash Sonawane

Posted on

How to Deploy a Dockerized App on ECS (with Fargate) ๐Ÿšข๐Ÿ”ฅ

"You mean I can run containers on AWS without managing servers?"

Yes. Thatโ€™s the magic of ECS with Fargate โ€” AWS runs the servers, and you just run your containers. ๐ŸŽ‰

In this beginner-friendly guide, weโ€™ll walk through deploying a Dockerized app to Amazon ECS using Fargate, step by step, using plain English, code snippets, and real-world metaphors.

Letโ€™s go from local Docker image to live app on AWS โ€” in under 20 minutes.


๐Ÿง  Why ECS + Fargate?

ECS (Elastic Container Service) is AWSโ€™s managed container orchestration.

Fargate is the serverless engine behind it โ€” you donโ€™t manage EC2s, VMs, or clusters.

Think of ECS as a pizza restaurant.

  • With EC2 launch type: you bring your own oven.
  • With Fargate: AWS brings the oven. You just bring the ingredients (containers).

๐Ÿงฐ What Youโ€™ll Need

  • AWS account
  • Docker installed
  • A simple app (e.g., Node.js, Python, HTML)
  • AWS CLI & ECS CLI installed (optional but helpful)

๐Ÿงช Step-by-Step: Deploy Your App with ECS + Fargate

1. Dockerize Your App

Here's a basic Dockerfile for a Node.js app:

FROM node:18
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["node", "index.js"]
Enter fullscreen mode Exit fullscreen mode

Build and tag it:

docker build -t my-app .
Enter fullscreen mode Exit fullscreen mode

2. Push to Amazon ECR (Elastic Container Registry)

Create an ECR repo:

aws ecr create-repository --repository-name my-app-repo
Enter fullscreen mode Exit fullscreen mode

Authenticate Docker:

aws ecr get-login-password | docker login --username AWS --password-stdin <your-account-id>.dkr.ecr.<region>.amazonaws.com
Enter fullscreen mode Exit fullscreen mode

Tag and push:

docker tag my-app:latest <your-ecr-url>/my-app-repo:latest
docker push <your-ecr-url>/my-app-repo:latest
Enter fullscreen mode Exit fullscreen mode

3. Create ECS Cluster

Go to ECS โ†’ Create Cluster โ†’ Choose "Networking only (Fargate)"

Name it my-app-cluster


4. Define Task Definition

  • Go to ECS โ†’ Task Definitions โ†’ Create New
  • Choose Fargate
  • Add container with:

    • Image: your-ecr-url/my-app-repo:latest
    • Port mappings: 80 (or whatever your app uses)
  • Set CPU: 256 and Memory: 512 (or as needed)


5. Create Service

  • ECS โ†’ Clusters โ†’ my-app-cluster
  • Click Create Service
  • Launch type: Fargate
  • Task Definition: the one you just created
  • Desired tasks: 1
  • Select a VPC and subnets
  • Enable public IP if hosting a public web app
  • Create a new Security Group allowing port 80

Click "Create Service" โ€” wait for it to spin up โ˜๏ธ


6. Access Your App!

Once the task is running:

  • Go to EC2 โ†’ Network Interfaces
  • Find the ENI attached to your task
  • Copy its public IP

Open in browser:

http://<public-ip>
Enter fullscreen mode Exit fullscreen mode

Boom ๐Ÿ’ฅ! Your containerized app is now live.


๐Ÿง  Why Devs Love ECS + Fargate

  • โœ… No servers to manage
  • โœ… Pay only for what you use
  • โœ… Scales easily
  • โœ… Deep AWS integration (CloudWatch, IAM, etc.)
  • โœ… Great for microservices

๐Ÿ” Bonus: Add HTTPS with Load Balancer + ACM

Want a custom domain and SSL?

  • Use Application Load Balancer
  • Add HTTPS listener
  • Use AWS Certificate Manager (ACM) to create free SSL certs

๐Ÿ“ฆ Final Thoughts + Whatโ€™s Next

You just deployed a production-grade app using Docker + AWS โ€” no EC2s, no pain.

Next steps?

  • Add autoscaling
  • Use CodePipeline for CI/CD
  • Add CloudWatch monitoring

๐Ÿ’ฌ Your Turn: Did You Deploy It?

Was this guide helpful?
Are you stuck on a step?
Got your app running?

๐Ÿ‘‡ Drop your questions, success stories, or URLs in the comments.

If this made ECS + Fargate feel easier โ€” hit โค๏ธ and share with a dev friend who's drowning in EC2 setup hell.

Letโ€™s Docker smarter, not harder. ๐Ÿงก

Top comments (1)

Collapse
 
anik_sikder_313 profile image
Anik Sikder

This guide is gold. especially the pizza metaphor ๐Ÿ•. ECS + Fargate always felt intimidating, but breaking it down like this makes it way more approachable. Got my app running in under 30 minutes. Thanks for making serverless feel less scary!