This guide explains the steps I followed to containerize an application and deploy it to AWS using Docker, Terraform, ECS Fargate, and GitHub Actions.
The goal is simple.
Build the app, package it in Docker, store the image in ECR, run it on ECS Fargate, and automate the deployment with GitHub Actions.
1. Prepare the Application
Create a simple Node.js application.
Example project structure:
app/
server.js
package.json
Dockerfile
terraform/
Install dependencies:
npm install
Run the application locally to confirm it works.
node server.js
Open:
http://localhost:3000
2. Containerize the Application
Create a Dockerfile.
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install --production
COPY . .
EXPOSE 3000
CMD ["node", "app/server.js"]
Build the image:
docker build -t job-tracker-app .
Run the container locally:
docker run -p 3000:3000 job-tracker-app
Open the browser:
http://localhost:3000
3. Create an Amazon ECR Repository
Open AWS Console.
Go to:
ECR → Create repository
Give it a name:
job-tracker-app
After creating the repository, push your Docker image.
Login to ECR:
aws ecr get-login-password --region us-east-1 \
| docker login --username AWS --password-stdin ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com
Tag the image:
docker tag job-tracker-app:latest ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/job-tracker-app:latest
Push the image:
docker push ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/job-tracker-app:latest
4. Provision Infrastructure with Terraform
Create infrastructure using Terraform.
Resources created include:
- VPC
- Public subnets
- Security groups
- ECS cluster
- ECS service
- Application Load Balancer
Initialize Terraform:
terraform init
Apply infrastructure:
terraform apply
Confirm the ECS service is running.
You should see:
1/1 tasks running
5. Verify the Application
Once the ECS task is running, the application can be accessed using the public IP assigned to the service.
Open the IP address in the browser to confirm the application is working.
6. Push the Project to GitHub
Initialize git:
git init
git add .
git commit -m "Initial commit"
Create a repository on GitHub.
Connect the repo:
git remote add origin YOUR_REPO_URL
git branch -M main
git push -u origin main
7. Add GitHub Actions for CI/CD
Create this folder in your repository:
.github/workflows
Create a file:
deploy.yml
The workflow should:
- build the Docker image
- push the image to ECR
- update the ECS service
8. Add AWS Credentials to GitHub
In your GitHub repository, go to:
Settings → Secrets → Actions
Add these secrets:
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
These allow GitHub Actions to deploy to AWS.
9. Trigger Deployment
Push a change to the repository:
git push
GitHub Actions will start the pipeline.
The pipeline will:
- build the Docker image
- push it to ECR
- update the ECS service
Your application will be redeployed automatically.
Final Result
You now have:
- A containerized application.
- Infrastructure created with Terraform.
- Containers running on ECS Fargate.
- Automated deployment using GitHub Actions.
This setup removes manual deployment and keeps the application updated whenever code changes.
If you found this article helpful, share it with others who may find it interesting.
Other Helpful Resources
Stay updated with my projects by following me on Twitter, LinkedIn, and GitHub.
Thank you for reading



Top comments (0)