If you’ve ever built a Node.js application and wanted a better way to run it on any computer without worrying about setup issues, Docker is the tool you need. Docker helps developers create containers — lightweight, standalone environments that include everything your app needs to run.
In this guide, you’ll learn how to build and run a simple Node.js Express app inside a Docker container. This is perfect for beginners who are just getting started with backend development and want to explore how Docker can simplify development and deployment.
- Node.js and npm installed
- Docker installed
- Basic understanding of Node.js and Express
- Text editor like VS Code
mkdir node-docker-app
cd node-docker-app
npm init -y
Install Express:
npm install express
Then create index.js
:
const express = require('express');
const app = express();
const PORT = 3000;
app.get('/', (req, res) => {
res.send('Hello from Dockerized Node.js App!');
});
app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
});
A Dockerfile contains instructions to build a Docker image for your app.
Create a file named Dockerfile
:
# Use Node.js official image
FROM node:18
# Create app directory
WORKDIR /app
# Copy package files and install
COPY package*.json ./
RUN npm install
# Copy the app code
COPY . .
# App will run on port 3000
EXPOSE 3000
# Start the app
CMD ["node", "index.js"]
.dockerignore
is like .gitignore
, it tells Docker what to ignore during the image build.
Create a file named .dockerignore
:
node_modules
npm-debug.log
docker build -t node-docker-app .
docker run -p 3000:3000 node-docker-app
Now visit: http://localhost:3000
In this guide, we walked through building a simple Node.js Express application and running it inside a Docker container. Whether you're a beginner or someone trying Docker for the first time, this setup is a great way to understand how modern applications are packaged and deployed.
Author: Bishal Kunwar
🗓️ Published: April 13, 2025
📰 Subscribe to my newsletter for more content like this!