How to Create a Docker Image of Your Node.js App & Push to Docker Hub
In this step-by-step tutorial, learn how to containerize your Node.js application by creating a Docker image and pushing it to Docker Hub. Whether you're a beginner or looking to refine your Docker skills, this video covers everything:
✔️ Setting up a Node.js app
✔️ Writing a Dockerfile
✔️ Building the Docker image
✔️ Running the container locally
✔️ Tagging and pushing the image to Docker Hub
This tutorial is perfect for developers looking to streamline their deployment process with Docker. Don’t forget to like, subscribe, and share if you find it helpful!
docker,docker tutorial
what is docker,docker image
docker nodejs
docker container
docker tutorial for beginners
learn docker
docker compose
nodejs app docker container
docker images
docker for beginners
docker explained
build docker image with nodejs app
how to create a docker file
what is docker container
how to create docker image for node js application
how to create docker image for node js
docker node js express
docker express
docker node js
push image to docker hub
Single stage build dockerfile
1. Use an official Node.js runtime as a parent image
FROM node:18
2. Set the working directory inside the container (root is /usr/src/app)
WORKDIR /usr/src/app
3. Copy package.json and package-lock.json from the current directory (backend)
COPY package*.json ./
4. Install any needed dependencies
RUN npm install --production
5. Copy the rest of the backend directory content to the working directory
COPY . .
6. Set the WORKDIR to the src folder inside the container
WORKDIR /usr/src/app/src
7. Expose the necessary port (example: 3000)
EXPOSE 8080
8. Command to run the app
CMD ["node", "index.js"]
//Docker command
docker build -t docker_image .
docker run -p 8080:8080 docker_image
Push the image to dockerhub
docker tag docker_image brajeshsaxena01/docker_image
docker push brajeshsaxena01/docker_image
Multistage build Dockerfile
Stage 1: Build stage
FROM node:18 AS builder
Set the working directory inside the container
WORKDIR /usr/src/app
Copy package.json and package-lock.json to the working directory
COPY package*.json ./
Install all dependencies (including devDependencies)
RUN npm install
Copy the rest of the backend directory to the working directory
COPY . .
Stage 2: Production image stage
FROM node:18-alpine
Set the working directory for the production image
WORKDIR /usr/src/app
Copy only the necessary files from the build stage
COPY --from=builder /usr/src/app /usr/src/app
Install only production dependencies
RUN npm prune --production
Set the working directory to the src folder inside the container
WORKDIR /usr/src/app/src
Expose the necessary port (example: 8080)
EXPOSE 8080
Command to run the app
CMD ["node", "index.js"]
//Login to docker hub
docker login
docker pull brajeshsaxena01/docker_image:latest
#Nodejs #Docker #DockerHub #DevOps #Tutorial