Learn how to deploy a Node.js app with Docker on Ubuntu 24.04 step by step. Install Docker, configure Nginx reverse proxy, secure with Let’s Encrypt SSL.
Introduction
In this tutorial, we demonstrated how to deploy a Node.js application using Docker on Ubuntu 24.04. We created a simple Hello World project, containerized it using a production-ready Dockerfile, configured Nginx as a reverse proxy, and secured the application with a free SSL certificate using Certbot.
This step-by-step guide is designed to help us deploy Node.js applications in a clean, modern, and secure way using containerization and HTTPS. The process follows current best practices and works reliably on Ubuntu 24.04 LTS.
Prerequisites
Before we begin, let’s ensure we have the following in place:
- A Ubuntu 24.04 dedicated server or KVM VPS.
- A basic programming knowledge.
- A domain name pointing to server IP.
Deploy Node.js App with Docker on Ubuntu 24.04 (Nginx + SSL Guide)
Step 1: Update the Server
First, we update our system packages to ensure everything is current.
sudo apt update && sudo apt upgrade -y
Step 2: Install Docker on Ubuntu 24.04
We install Docker from the official Docker repository.
sudo apt install -y ca-certificates curl gnupg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl enable docker
sudo systemctl start docker
To verify Docker is installed:
docker --version
Step 3: Create a Simple Hello World Node.js Application
Now we create a small Node.js project.
Create a new project directory:
mkdir node-docker-app
cd node-docker-app
Create a package.json file:
nano package.json
Add following content:
{
"name": "hello-node",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"express": "^4.18.2"
}
}
Save and exit the file.
Now create the application file:
nano index.js
Add following content
const express = require("express");
const app = express();
app.get("/", (req, res) => {
res.send("Hello from our Dockerized Node.js app!");
});
app.listen(3000, () => {
console.log("Server running on port 3000");
});
Save and exit the file.
Step 4: Create the Dockerfile
Inside the same project directory, create a file named Dockerfile.
nano Dockerfile
Add the following content:
FROM node:24-alpine
WORKDIR /app
COPY package.json ./
RUN npm install --production
COPY . .
EXPOSE 3000
CMD ["node", "index.js"]
Save and exit the file.
This Dockerfile uses the Node.js 24 LTS image, installs dependencies, and starts the application.
Step 5: Build and Run the Docker Container
Build the Docker image:
docker build -t hello-node-app .
Run the container:
docker run -d -p 3000:3000 --name hello-node-container hello-node-app
Step 6: Install Nginx on Ubuntu 24.04
Now we install Nginx to act as a reverse proxy.
sudo apt install nginx -y
sudo systemctl enable nginx
sudo systemctl start nginx
Add HTTP and HTTPS ports in the firewall:
sudo ufw allow 80,443/tcp
Step 7: Configure Nginx Reverse Proxy
Create a new Nginx configuration file:
sudo nano /etc/nginx/sites-available/nodeapp
Add this configuration (replace example.com with our domain):
server {
listen 80;
server_name example.com www.example.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Enable the configuration:
sudo ln -s /etc/nginx/sites-available/nodeapp /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
Step 8: Install Certbot and Enable HTTPS
Ubuntu 24.04 uses Snap for Certbot installation.
Install Certbot:
sudo apt install certbot python3-certbot-nginx -y
Now generate the SSL certificate:
sudo certbot --nginx -d example.com -d www.example.com
Follow the prompts and enter a valid email address.
After successful installation, our website will automatically be accessible over HTTPS.
Test automatic renewal:
sudo certbot renew --dry-run
Step 9: Access Application
Finally, navigate to your browser and access:
https://example.com
You will see:
Hello from our Dockerized Node.js app!
Step 10: How to Update the Node.js Project
When we update our Node.js project (for example, we modify index.js or install a new dependency), Docker will not automatically update the running container. We must rebuild the image and restart the container.
First, go to the project directory:
cd ~/node-docker-app
If we are pulling updates from Git:
git pull origin main
After the code is updated, rebuild the Docker image:
docker build -t hello-node-app .
Now stop and remove the old container:
docker stop hello-node-container
docker rm hello-node-container
Start a new container using the updated image:
docker run -d -p 3000:3000 --name hello-node-container hello-node-app
That’s it. The updated version of the project is now live.
Conclusion
We have successfully deployed a Dockerized Node.js application on Ubuntu 24.04 and configured it with Nginx and HTTPS. This setup provides a stable and scalable foundation for running production applications.
By using Docker for application isolation, Nginx for traffic management, and Certbot for SSL security, we ensure that our deployment is secure, maintainable, and easy to update. This approach can be reused for future Node.js projects with minimal adjustments.

