π Deploy a Node.js App in Docker on Rocky Linux EC2 (Without Key Pair) Using Only Vi Editor


Are you a beginner looking to level up your DevOps and cloud skills by deploying a Node.js app in Docker on an AWS EC2 instance β but using only vi
editor and no SSH key pair?
This hands-on tutorial walks you through everything from launching your EC2 instance to building and running your containerized app. Let's go! πͺ
π§Ύ Prerequisites
AWS account (Free Tier)
Basic terminal familiarity
No SSH key pair required!
βοΈ Step 1: Launch a Rocky Linux EC2 Instance
Go to AWS Console β EC2 β Launch Instance
Configuration:
Name:
rocky-node
AMI: Rocky Linux 9 (x86_64)
Instance type:
t2.micro
(Free Tier)Key Pair: Proceed without key pair
Security Group:
Allow SSH (22)
Allow TCP (3000)
Launch your instance.
π‘ Step 2: Connect via EC2 Instance Connect
From your EC2 dashboard:
Select the instance β Click Connect
Use EC2 Instance Connect
Boom! Youβre in your Rocky Linux server! π»
π³ Step 3: Install Docker and Node.js
sudo dnf -y update
sudo dnf -y install docker
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -aG docker ec2-user
newgrp docker
Now install Node.js:
curl -fsSL https://rpm.nodesource.com/setup_18.x | sudo bash -
sudo dnf install -y nodejs
π Step 4: Create Your Node App
mkdir node-app && cd node-app
Create server.js
using vi
:
vi server.js
Press i
to insert and paste:
const http = require('http');
const server = http.createServer((req, res) => {
res.end('Hello from Rocky Linux + Node.js!');
});
server.listen(3000, () => {
console.log('Server running on port 3000');
});
Exit with Esc β :wq β Enter
Create package.json
using vi
:
vi package.json
Paste:
{
"name": "rocky-node",
"version": "1.0.0",
"description": "Simple Node.js server",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"author": "Sonica",
"license": "ISC"
}
π¦ Step 5: Create Dockerfile Using vi
vi Dockerfile
Paste:
FROM rockylinux:9
RUN dnf -y update && \
dnf -y install nodejs npm && \
dnf clean all
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
π§ Step 6: Build Docker Image
docker build -t rocky-node .
βΆοΈ Step 7: Run Your Container
docker run -d -p 3000:3000 rocky-node
Check with:
docker ps
π Step 8: Access Your App in Browser
Go to:
http://<YOUR_EC2_PUBLIC_IP>:3000
β Youβll see:
Hello from Rocky Linux + Node.js!
π Optional: Auto-start on Reboot
docker run -d -p 3000:3000 --restart always rocky-node
π§ Learnings
β
Launched a Linux EC2 without a key pair
β
Used vi
editor like a pro
β
Installed Docker + Node.js
β
Dockerized and deployed a custom Node app
β
Practiced real DevOps and Linux skills hands-on
πββοΈ Want More?
I'm working on more beginner-friendly Linux & DevOps posts! Follow me for updates or drop your questions in the comments.
Subscribe to my newsletter
Read articles from Sonica Sonawane directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Sonica Sonawane
Sonica Sonawane
Hi, I'm Sonica! π Iβm currently diving into the world of DevOps, focusing on AWS, Docker, Kubernetes, Linux, and GitHub. My passion lies in automating systems, building cloud infrastructure, and optimizing workflows. Iβm committed to continuous learning, hands-on projects, and sharing my journey with others in the tech community. Before shifting to DevOps, I worked in IT Sales, where I gained valuable skills in client communication, requirement gathering, and problem-solving. This experience taught me how to connect technical solutions to business needs, which has been instrumental as I transition into DevOps, where technical expertise and problem-solving go hand in hand. Now, Iβm eager to apply my sales experience alongside my growing technical skills in cloud engineering and DevOps. Join me as I explore the latest trends, challenges, and solutions in the world of cloud computing!