Hi everyone,
My name is Soumen Bhunia. This is my first blog. In this blog, I build and deploy my first Node.js app using Docker, hosted on an AWS EC2 instance, and connected to a MySQL database hosted via Amazon RDS
Technologies Used
- Node.js – JavaScript runtime to build the server-side app
- Docker – For containerizing the Node.js app
- Amazon EC2 – Virtual server for running the Docker container
- Amazon RDS (MySQL) – Managed MySQL database service
- AWS Security Groups – For access control to EC2 and RDS
Step-by-Step Setup Guide
Step 1: Create an RDS MySQL Instance
- Go to Amazon RDS Console.
- Click Create Database.
- Choose:
- Engine type: MySQL
- Use case: Free Tier
- Under Settings:
- Set a DB instance identifier
-
Master username:
admin
-
Master password: Set a secure password (avoid special characters like
@
,%
, etc.)
- In Connectivity:
- Enable Public access = Yes (for development purposes)
- Create a new VPC security group
- Add an inbound rule to allow MySQL/Aurora (port
3306
) from Anywhere (0.0.0.0/0)
After RDS is created, copy the endpoint/hostname — you'll use it to connect your app to the database.
Step 2: Launch and Configure an EC2 Instance
Go to Amazon EC2 Console.
-
Launch a new instance:
- Amazon Linux 2 AMI (Free Tier eligible)
- Choose t2.micro (Free Tier)
-
In Security Group, allow:
- HTTP (port 80) – for web traffic
- SSH (port 22) – for connecting to the instance
- Optional: Restrict access by IP for SSH
Step 3: Install Docker on EC2
Once connected to EC2, run the following:
sudo yum update -y
sudo yum install -y docker
sudo service docker start
sudo usermod -aG docker ec2-user
Important: Log out and log back in to activate Docker permissions for ec2-user
.
Step 4: Run the Dockerized Node.js App
Pull the Docker image:
sudo docker pull philippaul/node-mysql-app:02
Then run your container, replacing the values with your actual RDS credentials:
docker run --rm -p 80:3000 \
-e DB_HOST="your-db-endpoint.rds.amazonaws.com" \
-e DB_USER="admin" \
-e DB_PASSWORD="your-db-password" \
-d philippaul/node-mysql-app:02
Your app should now be accessible at your EC2 public IP on port 80.
Web interface screenshot
Optional: Test the MySQL Connection
You can test connecting to the database from inside EC2 using a MySQL Docker client:
docker run -it --rm mysql:8.0 mysql \
-h your-db-endpoint.rds.amazonaws.com \
-u admin -p
Enter your password when prompted. If you connect successfully — your EC2 can talk to your RDS instance.
Thanks for Reading!
Hope this gives you some perspective.
Coming Up Next:
More hands-on cloud projects and DevOps tips — stay tuned!
Let’s Connect:
Share your thoughts in the comments or reach out on LinkedIn.Your feedback means a lot!
Top comments (0)