I feel very embarrassed when I claim to be a backend developer without basic Docker knowledge. Doesn't it feel the same to you?
Prerequisites
Before I start, make sure you have the following installed:
- Node.js and npm:.You can download and install it from the Node.js official website.
2.Docker: Download and install form Docker's Official Website.
Step1: Create a Nodejs App or use my sample Nodejs App by cloning it
git clone https://github.com/AbhishekCS3459/Node_Docker_Demo
cd Node_Docker_Demo
npm install
Step2 (Optional): Run the below command to run the application demo
npm run start
Step3: Run the below command to build the docker image
docker build YOUR_IMAGE_NAME .
Note: . represents you are running the above command in the current directory where your node application exists.
Step4: Check whether your image has build or not by running the below command
docker images
Step5: Run the container using the following command
docker run -it -p 3000:3000 YOUR_IMAGE_NAME
Note: Here -it is a flag to run the container in interactive mode and -p for mapping the container port with the external port
Container:
A Docker container is a lightweight, standalone, executable package that includes everything needed to run a piece of software, including the code, runtime, system tools, libraries, and settings. Containers isolate the application from its environment, ensuring consistent behavior across different environments.
Deploy the Image to Docker Hub
To share your Docker image with others, you can deploy it to Docker Hub.
Step 1: Login to Docker Hub
First, log in to Docker Hub using the command:
docker login
You will be prompted to enter your Docker Hub username and password.
Step 2: Tag Your Image
Tag your Docker image with your Docker Hub repository name. Replace YOUR_DOCKERHUB_USERNAME and YOUR_IMAGE_NAME with your Docker Hub username and the name of your image:
docker tag YOUR_IMAGE_NAME YOUR_DOCKERHUB_USERNAME/YOUR_IMAGE_NAME
Step 3: Push Your Image to Docker Hub
Push the tagged image to Docker Hub:
docker push YOUR_DOCKERHUB_USERNAME/YOUR_IMAGE_NAME
You can now see your image on Docker Hub and share it with others!
If you want to ask, ping me below.
Connect with me on Linkedin:
linkedin/abhishekverman.
Further Reading: Dockerize a Golang Application
Top comments (3)
If you want to ask, ping me below.
Connect with me on Linkedin:
linkedin/abhishekverman
I made this also! But, for bundled React application. Go check it out...
Dockerize Production React.js
M. Akbar Nugroho ・ Oct 7 '22
That's insightful