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!