How to Deploy Node.js Code into Docker

Abhishek Kumar Gupta
2 min readJan 3, 2021

--

Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. to know more about docker please click here.

At present concept of Micro-services are increasing day by day. As well as mostly company as well as developer prefer PaaS (Platform as a Services) and SaaS (Software as a services) rather than setting the complete development environment. Same happen with me here client want’s separate services and he want’s that is deploy each service into separate docker container. That’s why this Idea comes into my mind to write all the steps of deployment into a block so that I, my team and the other one who wanted to deploy the code into Docker can go through the steps easily.

Now Let’s go through the step by step.

Step One:
Create new file name as “Dockerfile” at the root folder of your project and add the following code.

# Specify a base imageFROM node:14-alpineWORKDIR /app      #You can choose another directory of your choice
COPY package.json ./
RUN npm install
COPY ./ ./
CMD ["npm", "start"]

Step Two:
Create new file name as “.dockerignore” and add the following code.

node_modules

Step Three:
Now run the following code to into the terminal.
docker build -t <container-name>

docker build -t abhishek/my-service .

Step Four:
Now run the final command to run your code.
docker run <container-name or container-id>

docker run abhishek/my-service

If you are curious to learn new things please like and subscribe my YouTube channel. Also like my facebook page for new notifications.

To tell us about your requirement please fill the form: https://docs.google.com/forms/d/1uh343ab8uwVhCpozi_etFyV67f6zVoIiMlrYKLwOgnE/prefill

--

--

Abhishek Kumar Gupta
Abhishek Kumar Gupta

Written by Abhishek Kumar Gupta

Web and Native Mobile App Developer.

No responses yet