AWS Builder Center
From Docker to AWS Fargate: Deploying Containerized Applications Without Managing Servers

From Docker to AWS Fargate: Deploying Containerized Applications Without Managing Servers

Learn how to deploy a Dockerized Node.js application on AWS without managing servers! 🚀 In this hands-on guide, we explore Docker, Amazon ECR, Amazon ECS, and AWS Fargate to build a scalable, serverless container deployment workflow. From creating Docker images and configuring ECS services to testing automatic task replacement, troubleshooting deployment issues, and following production best practices, this article covers the essential steps.

From Docker to AWS Fargate: Deploying Containerized Applications Without Managing Servers
Introduction
Deploying applications in the cloud has changed significantly with containerization and serverless computing.
Traditionally, deploying a Node.js application involved launching an EC2 instance, installing dependencies, configuring Docker, managing networking, and maintaining the server.
But what if we could deploy Docker containers without managing the underlying servers?
That’s where Amazon ECS and AWS Fargate come into the picture.
In this article, we’ll explore how to containerize an application, store its Docker image in Amazon Elastic Container Registry (ECR), deploy it using Amazon Elastic Container Service (ECS), and understand how AWS automatically replaces failed tasks.
1. Understanding the AWS Services
Before deployment, let’s understand the three main technologies.
Docker
Docker packages an application and its dependencies into a container image, helping it run consistently across different environments.
Amazon ECR (Elastic Container Registry)
Amazon ECR is a managed container registry that stores Docker and OCI-compatible container images.
Instead of maintaining a private Docker registry, we can store and manage our application images directly in AWS.
Amazon ECS (Elastic Container Service)
Amazon ECS is a container orchestration service that helps deploy, manage, and scale containerized applications.
AWS Fargate
AWS Fargate provides serverless compute capacity for containers.
With Fargate, AWS manages the underlying infrastructure, allowing developers to focus on their applications.
2. Understanding the Deployment Architecture
Our application follows this workflow:
Application Source Code → Docker Image → Amazon ECR → Amazon ECS → AWS Fargate → Running Application
Each component has a specific responsibility:
  • Docker packages the application.
  • Amazon ECR stores the container image.
  • Amazon ECS manages container deployment.
  • AWS Fargate provides the compute resources.
  • Amazon CloudWatch can collect application logs and monitoring information.
The biggest advantage is that we don’t need to launch or maintain an EC2 instance for our application containers.
3. Prerequisites
Before starting, ensure you have:
  • An AWS account with appropriate permissions
  • Docker installed on your local machine
  • A working application with a Dockerfile
  • AWS CLI configured locally for pushing images to private ECR
  • Basic knowledge of AWS networking
For this demonstration, consider a Node.js backend running on port 3000.
4. Step 1: Containerize the Application
First, create a Dockerfile in the root directory of the Node.js project.
Example Dockerfile:
FROM node:22-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
EXPOSE 3000
CMD ["node", "server.js"]
Ensure that server.js is your application’s actual entry point and that your application listens on 0.0.0.0.
Build the Docker image:
docker build -t my-node-app:v1 .
Test it locally:
docker run --rm -p 3000:3000 my-node-app:v1
Open  http://localhost:3000  to verify that the application is running.
For an Apple Silicon Mac, check that your image architecture matches the CPU architecture configured for your Fargate task.
5. Step 2: Create an Amazon ECR Repository
Now that the application image is ready, we need a registry to store it.
  1. Open the AWS Management Console.
  1. Search for Amazon ECR.
  1. Navigate to Private repositories.
  1. Click Create repository.
  1. Enter a repository name, such as my-node-app.
  1. Configure the repository settings and click Create.
After creating the repository, select it and click View push commands.
AWS provides the commands required to authenticate Docker, tag the image, and push it to ECR.
Once the push is complete, your image becomes available through an ECR repository URI.
This URI will be used in the ECS task definition.
6. Step 3: Create an ECS Cluster
Next, create a cluster to organize our container workloads.
  1. Open Amazon ECS in the AWS Console.
  1. Navigate to Clusters.
  1. Click Create cluster.
  1. Enter the cluster name my-fargate-cluster.
  1. Configure the cluster for AWS Fargate capacity.
  1. Create the cluster.
An ECS cluster acts as a logical grouping for our services and tasks.
7. Step 4: Create a Task Definition
A task definition describes how ECS should run our containers.
Navigate to ECS → Task definitions → Create new task definition.
Configure:
  • Task definition family: my-node-task
  • Launch type: AWS Fargate
  • Operating system: Linux
  • CPU: 0.25 vCPU
  • Memory: 0.5 GB
  • Container name: node-container
  • Image URI: Your Amazon ECR image URI
  • Container port: 3000
Select a suitable task execution IAM role so Fargate can retrieve the image from ECR and send logs to CloudWatch when configured.
Finally, create the task definition.
8. Step 5: Create an ECS Service
Now comes the main deployment stage.
Open your ECS cluster and navigate to the Services tab.
Click Create and configure:
  • Service name: node-app-service
  • Task definition: my-node-task
  • Compute option: Fargate
  • Desired task count: 1
For a simple learning environment, select an appropriate public subnet and enable public IP assignment.
Configure a security group that allows inbound traffic to port 3000 from your testing IP address.
Create the service and monitor the deployment.
ECS will attempt to start the application container using AWS Fargate.
Once the task reaches the RUNNING state, navigate to its networking details to find the public IP address.
Test the application using:
If everything is configured correctly, your Node.js application should be accessible.
Important: Direct public-IP access is useful for a demonstration. For production, prefer private tasks behind an Application Load Balancer with HTTPS and appropriate security controls.
9. Step 6: Understanding Automatic Task Replacement
One of the most useful features of an ECS service is maintaining the desired number of running tasks.
Suppose we configure:
Desired task count = 1
If the running task unexpectedly stops, the ECS service scheduler attempts to launch a replacement task.
We can explore this behavior with a simple experiment:
  1. Open your ECS cluster.
  1. Select the running service.
  1. Navigate to the Tasks tab.
  1. Select the running task.
  1. Choose Stop task.
  1. Monitor the service’s Tasks and Events tabs.
Because the service’s desired count remains one, ECS attempts to launch another task.
This behavior is known as automatic task replacement.
It is important to understand that ECS launches a replacement task rather than simply restarting the original container.
Also, automatic replacement doesn’t guarantee zero downtime. For higher availability, use multiple tasks across Availability Zones with appropriate load balancing and health checks.
10. Step 7: Updating the Application
Suppose we make changes to our Node.js application.
Instead of manually logging into a server and replacing files, we can follow a container-based deployment approach.
Updated Code → New Docker Image → Push to ECR → New Task Definition Revision → Update ECS Service
A recommended approach is to use versioned image tags such as v1, v2, and v3.
After pushing an updated image:
  1. Open the existing task definition.
  1. Create a new revision referencing the updated image.
  1. Open the ECS service.
  1. Select Update service.
  1. Select the new task definition revision.
  1. Deploy the update.
ECS can perform a rolling deployment, gradually replacing older tasks with updated versions according to the deployment configuration.
This workflow makes application releases more manageable and repeatable.
11. Common Deployment Issues
While working with ECS and Fargate, developers may encounter several problems.
Task stops immediately
Check container logs, the application’s startup command, environment variables, and ECS service events.
CannotPullContainerError
Verify the ECR image URI, image architecture, IAM task execution role, and network connectivity required to retrieve the image.
Application is not accessible
Check the security group inbound rules, public IP assignment, subnet routing, container port mapping, and application listening address.
Updated application is not appearing
Confirm that the new image was pushed and the ECS service is running the correct task definition revision.
Amazon CloudWatch Logs and ECS service events are valuable troubleshooting resources.
12. Production Best Practices
Before moving from a demonstration to a production environment, consider these practices:
  • Run multiple tasks across Availability Zones for improved availability.
  • Use an Application Load Balancer and HTTPS.
  • Keep application tasks in private subnets where practical.
  • Enable container health checks and appropriate monitoring.
  • Store sensitive configuration in AWS Secrets Manager or Systems Manager Parameter Store.
  • Use least-privilege IAM roles.
  • Implement CI/CD for automated deployments.
  • Monitor CPU, memory utilization, logs, and costs.
Remember that Fargate is serverless, but it is not free. Compute resources, storage, networking, and related AWS services can generate charges.
Delete unused ECS services, load balancers, and other test resources when the exercise is complete.
13. Key Learnings
Working with Docker, Amazon ECR, ECS, and Fargate helps explain several important DevOps concepts:
  1. Containerization: Applications and their dependencies can be packaged consistently.
  1. Container orchestration: ECS manages deployment and desired task counts.
  1. Serverless containers: Fargate removes the need to maintain container-hosting EC2 instances.
  1. Self-healing behavior: ECS services attempt to replace stopped or unhealthy tasks.
  1. Scalability: ECS services can increase or decrease task counts, including through configured automatic scaling.
  1. Release management: Versioned images and task definition revisions support controlled deployments.
Conclusion
Docker and AWS Fargate provide a powerful combination for deploying modern containerized applications.
By integrating Docker with Amazon ECR and ECS, developers can build an efficient deployment workflow without managing the underlying container servers.
For anyone learning Cloud Computing or DevOps, deploying an application on ECS with Fargate is an excellent practical exercise.
The most valuable lesson is that modern DevOps is not only about running applications. It is about making deployments repeatable, scalable, observable, and resilient.
Happy Learning and Happy Building! 🚀
References
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article