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

Sonica SonawaneSonica Sonawane
3 min read

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

  1. Go to AWS Console β†’ EC2 β†’ Launch Instance

  2. 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.

0
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!