
From Docker to AWS Fargate: A Complete ECR and ECS Deployment Journey
Learn how a Docker application moves from local development to Amazon ECR and finally runs as a production-ready container on Amazon ECS with AWS Fargate.
š From Docker to AWS Fargate: Complete Container Deployment Journey
Containers have changed the way applications are built, shipped, and deployed. Instead of configuring the same environment repeatedly, we can package an application with its dependencies into a Docker image and deploy that image across different environments.
In this hands-on AWS lab, I learned how a Dockerized application moves from local development to a running application on AWS using Amazon ECR, Amazon ECS, and AWS Fargate.
The complete journey was:
Docker ā Amazon ECR ā ECS Task Definition ā ECS Cluster ā AWS Fargate ā Running Container ā Application
šļø Complete Architecture
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
šØāš» APPLICATION CODE
ā
ā¼
š³ DOCKER
Build Image
ā
ā¼
š¦ AMAZON ECR
Store Container Image
ā
ā Pull Image
ā¼
š ECS TASK DEFINITION
Container Blueprint
ā
ā¼
š¢ ECS CLUSTER
Manage Tasks
ā
ā¼
ā” AWS FARGATE
Run Containers
ā
ā¼
š RUNNING TASK
ā
ā¼
š APPLICATION
ā
ā¼
š¤ USER
The core idea is simple:
Docker builds the image, ECR stores the image, ECS manages the container, and Fargate provides the compute required to run it.
š³ 1. Docker: Building the Container Image
The journey starts with the application and a Dockerfile.
A Dockerfile contains instructions for creating a container image.
For example:
1
2
3
4
5
6
7
8
9
10
11
12
FROM python:3.11
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 8443
CMD ["python", "app.py"]
The Dockerfile defines:
- Base image
- Application dependencies
- Working directory
- Application files
- Container port
- Startup command
We can build the image using:
1
docker build -t my_app .
The process looks like:
1
2
3
4
5
6
7
8
9
10
Application Code
ā
ā¼
Dockerfile
ā
ā¼
docker build
ā
ā¼
Docker Image
The Docker image packages the application and its required environment into a portable unit.
š¦ 2. Amazon ECR: Storing the Docker Image
After creating the Docker image, we need somewhere to store it.
This is where Amazon Elastic Container Registry (ECR) comes in.
ECR is a managed container registry used to store Docker/container images.
An image can have an ECR URI such as:
1
356035958256.dkr.ecr.us-east-1.amazonaws.com/my_app:latest
Let's break it down:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
356035958256
ā
āāā AWS Account ID
dkr.ecr.us-east-1.amazonaws.com
ā
āāā ECR Registry
my_app
ā
āāā Repository
latest
ā
āāā Image Tag
The image can then be pushed into ECR:
1
2
docker push \
356035958256.dkr.ecr.us-east-1.amazonaws.com/my_app:latest
Now the Docker image is stored in Amazon ECR and can be pulled by ECS.
š·ļø 3. Docker Image Tagging
Before pushing the local Docker image to ECR, we associate it with the ECR repository using a tag.
For example:
1
2
docker tag my_app:latest \
356035958256.dkr.ecr.us-east-1.amazonaws.com/my_app:latest
The workflow becomes:
1
2
3
4
5
6
7
8
9
Local Docker Image
ā
ā docker tag
ā¼
ECR Image URI
ā
ā docker push
ā¼
Amazon ECR
The tag is important because it allows us to identify a particular image/version.
For example:
1
2
3
my_app:latest
my_app:v1
my_app:v2
š 4. Understanding the ECR Image URI
One of the most important concepts I learned was the ECR image URI.
Example:
1
356035958256.dkr.ecr.us-east-1.amazonaws.com/my_app:latest
This URI tells ECS exactly which container image it should pull.
However, it is important to understand:
The ECR image URI is NOT the URL used by users to access the application.
There are two completely different concepts.
š¦ ECR Image URI
1
356035958256.dkr.ecr.us-east-1.amazonaws.com/my_app:latest
Purpose:
1
2
3
Identify the Docker image
ā
ECS pulls this image
š Application URL
1
http://<PUBLIC-IP>:<PORT>
Purpose:
1
2
3
Identify the running application
ā
Users access the application
So:
1
2
3
4
5
6
7
ECR URI
ā
"Which image should ECS run?"
Public IP + Port
ā
"Where can users access the running application?"
This distinction is extremely useful when troubleshooting container deployments.
š 5. ECS Task Definition
After storing the image in ECR, ECS needs instructions describing how to run it.
This is the purpose of an ECS Task Definition.
Think of a task definition as a blueprint for a container.
It can specify:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Task Definition
ā
āāā Container Image
ā āāā my_app:latest
ā
āāā CPU
ā
āāā Memory
ā
āāā Container Port
ā
āāā Environment Variables
ā
āāā Container Configuration
For example:
1
2
3
4
5
6
7
8
9
10
11
Image:
356035958256.dkr.ecr.us-east-1.amazonaws.com/my_app:latest
CPU:
0.25 vCPU
Memory:
512 MB
Container Port:
8443
The important distinction is:
A task definition is not the running container. It is the blueprint used to create the running container.
š¢ 6. Amazon ECS Cluster
The next component is the Amazon Elastic Container Service (ECS) Cluster.
An ECS cluster provides a logical environment for running ECS tasks.
For example:
1
2
3
4
5
6
7
8
ECS Cluster
Lab_cluster
ā
āāāāāāāāāā“āāāāāāāāā
ā ā
ā¼ ā¼
Fargate Task Fargate Task
first_app my_second_app
A single cluster can contain multiple applications and tasks.
In the lab, I worked with multiple applications running as separate Fargate tasks inside the ECS cluster.
ā” 7. AWS Fargate
Now comes one of the most useful parts of the architecture: AWS Fargate.
Fargate is a serverless compute engine for containers.
It allows us to run ECS containers without directly managing the underlying servers.
With ECS on EC2, we would need to manage infrastructure such as:
1
2
3
4
5
6
7
You
ā
āāā EC2 Instances
āāā Operating Systems
āāā Capacity
āāā Server Maintenance
āāā Containers
With ECS + Fargate:
1
2
3
4
5
6
7
8
9
10
11
You
ā
āāā Define Container
āāā Define CPU / Memory
āāā Run Task
ā
ā¼
Fargate
ā
ā¼
AWS manages underlying infrastructure
This allows developers to focus more on the application and less on server management.
š 8. Running the Container
Once the ECS task is launched using Fargate, ECS pulls the Docker image from ECR.
The process is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Amazon ECR
ā
ā Pull Image
ā¼
ECS Task Definition
ā
ā¼
ECS Cluster
ā
ā¼
AWS Fargate
ā
ā¼
Running Container
ā
ā¼
Application
The running task can have networking information such as:
1
2
3
4
5
Public IP:
54.xxx.xxx.xxx
Port:
8443
The application can then be accessed using:
1
http://<PUBLIC-IP>:<PORT>
The complete request path is:
1
2
3
4
5
6
7
8
9
10
11
12
13
User
ā
ā¼
Public IP : Port
ā
ā¼
Fargate Task
ā
ā¼
Container
ā
ā¼
Application
š 9. Complete Deployment Workflow
The entire deployment process can be remembered using these steps.
Step 1: Create the Application
1
Application Code
ā¬ļø
Step 2: Create a Dockerfile
1
Dockerfile
ā¬ļø
Step 3: Build the Docker Image
1
docker build -t my_app .
ā¬ļø
Step 4: Tag the Image
1
2
docker tag my_app:latest \
356035958256.dkr.ecr.us-east-1.amazonaws.com/my_app:latest
ā¬ļø
Step 5: Push the Image to ECR
1
2
docker push \
356035958256.dkr.ecr.us-east-1.amazonaws.com/my_app:latest
ā¬ļø
Step 6: Create an ECS Task Definition
Configure:
1
2
3
4
5
Container Image
CPU
Memory
Container Port
Environment Variables
ā¬ļø
Step 7: Run the Task Using Fargate
1
2
3
4
5
6
7
8
9
10
ECS Cluster
ā
ā¼
Fargate Task
ā
ā¼
Running Container
ā
ā¼
Application
ā¬ļø
Step 8: Access the Application
1
http://<PUBLIC-IP>:<PORT>
š§© 10. Docker vs ECR vs ECS vs Fargate
| Technology | Purpose |
|---|---|
| š³ Docker | Builds and packages the application into a container image |
| š¦ Amazon ECR | Stores Docker/container images |
| š·ļø Image Tag | Identifies a particular image/version |
| š Task Definition | Defines how the container should run |
| š¢ Amazon ECS | Orchestrates and manages containers |
| ā” AWS Fargate | Provides serverless compute for running containers |
| š Public IP + Port | Provides access to the running application |
š„ 11. What Happens Behind the Scenes?
When a user accesses the application, several components work together.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
š¤ USER
ā
ā HTTP Request
ā¼
š Public Endpoint
ā
ā¼
ā” FARGATE TASK
ā
ā¼
š CONTAINER
ā
ā¼
š» APPLICATION
But before the container could run:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
š³ DOCKER
ā
ā Build
ā¼
Docker Image
ā
ā Push
ā¼
š¦ ECR
ā
ā Pull
ā¼
ECS Task Definition
ā
ā¼
ECS Cluster
ā
ā¼
FARGATE
ā
ā¼
Running Container
This is the complete container lifecycle.
šÆ 12. What I Learned From This Lab
This hands-on lab helped me understand the complete container deployment lifecycle instead of treating Docker, ECR, ECS, and Fargate as isolated technologies.
The key takeaways were:
š³ Docker
Docker packages an application and its dependencies into a portable container image.
š¦ Amazon ECR
ECR provides a managed registry where container images can be stored.
š·ļø Image Tagging
Docker images can be tagged with repository names and versions before being pushed to ECR.
š ECR Image URI
The ECR URI uniquely identifies the container image that ECS should pull.
š Task Definition
An ECS task definition acts as a blueprint that tells ECS how the container should run.
š¢ ECS Cluster
An ECS cluster provides a logical environment for running and managing ECS tasks.
ā” Fargate
Fargate provides serverless compute for running containers without directly managing servers.
š Fargate Task
A task represents an actual running instance of the container based on the task definition.
š Networking
The running application can be accessed through its configured network endpoint, such as a public IP and port.
š§ 13. The Most Important Mental Model
If there is only one diagram to remember, remember this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
šØāš» CODE
ā
ā¼
š³ DOCKER
Build Image
ā
ā¼
š¦ ECR
Store Image
ā
ā¼
š TASK DEFINITION
"How should it run?"
ā
ā¼
š¢ ECS
"Manage the task"
ā
ā¼
ā” FARGATE
"Run the task"
ā
ā¼
š CONTAINER
ā
ā¼
š APPLICATION
ā
ā¼
š¤ USER
š Final Takeaway
The entire architecture can be summarized in one sentence:
Docker builds the container image, Amazon ECR stores it, the ECS Task Definition describes how to run it, Amazon ECS manages the task, AWS Fargate provides the compute, and the running container serves the application to users.
This lab gave me a practical understanding of how modern containerized applications move from source code ā Docker image ā ECR ā ECS ā Fargate ā running application.
And that is considerably more useful than memorizing a pile of AWS acronyms and hoping the exam gods are feeling merciful. š
āļø Final Architecture at a Glance
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā AWS CLOUD ā
ā ā
ā š³ Docker ā
ā ā ā
ā ā Build ā
ā ā¼ ā
ā š¦ Docker Image ā
ā ā ā
ā ā Push ā
ā ā¼ ā
ā š¦ Amazon ECR ā
ā ā ā
ā ā Pull ā
ā ā¼ ā
ā š ECS Task Definition ā
ā ā ā
ā ā¼ ā
ā š¢ ECS Cluster ā
ā ā ā
ā ā¼ ā
ā ā” AWS Fargate ā
ā ā ā
ā ā¼ ā
ā š Running Container ā
ā ā ā
ā ā¼ ā
ā š Application ā
ā ā ā
āāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā
ā¼
š¤ USER
#AWS #Docker #ECR #ECS #Fargate #CloudComputing #Containers #DevOps #AWSBuilder
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article