Web Designing World | Logo

Here is this session we will see how we can set up Node JS server deployment using docker. we will deploy node js on ubuntu server using docker

Node.js is an open-source JavaScript platform source that allows using JS code without a browser. It’s written in JavaScript, C, and C ++. It can be installed on Windows, macOS x, Smart OS and Linux Are Licensed by MIT.

Node JS server deployment using docker

It allows the use of JS to build command-line tools. Allows processing of server-side scripts to generate dynamic pages. Instead of using a separate server-side and client-side language, it helps you combine your web application around individual applications.

Node JS is designed to build sensitive network systems. Node does not employ any key, so, you do not have to worry about locked calls. It does not use the standard concurrency model where OS threads are used. The queue-based network is inactive and difficult to use.

Just because it doesn’t use threads, doesn’t mean you can’t play multicores, you can use the child_process.fork API. It has a cluster module that lets you share the basics between processes to enable more customization of features.


Update Ubuntu System:

Before proceeding with the installation of any kind of package, use the following command to update your Ubuntu system. To execute this command, remember to login from non-root user with Sudo privileges. After execution of this command, you will be prompted to Is this ok? Type ‘y’ and hit Enter key.

Step 1:

# sudo apt update && sudo apt upgrade

Install software-properties-common:

Software-properties-common package is required to get the supported files for the installation of Docker CE. In order to install a software-properties-common package, follow the steps below.

Step 1:

To install apt-transport-https execute the command.

# sudo apt-get install apt-transport-https -y 

Install ca-certificates:

Ca-certificates is required for installation of Docker CE. In order to install ca-certificates, follow the steps below.

Step 1:

To install ca-certificates execute the command.

# sudo apt-get install ca-certificates -y 

Install curl:

Curl is required for installation of Docker CE. In order to install curl, follow the steps below.

Step 1:

To install curl execute the command.

# sudo apt-get install curl -y 

Install Docker CE:

To install Docker community edition, follow the steps below.

Step 1:

Add GPG key for Docker by executing command below.

# curl -fsSL
https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Step 2:

Execute the following command to verify the fingerprint of GPG key.

# sudo apt-key fingerprint 0EBFCD88

Step 3:

Now add the Docker repository by executing the command below.

# sudo add-apt-repository "deb [arch=amd64]
https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

Step 4:

Now update your system by executing command below to load added repository.

# sudo apt update

Step 5:

Execute the following command to install Docker.

# sudo apt install docker-ce

Step 6:

Now add your username to docker group by executing command below.

# sudo adduser aareez docker 

Step 6:

Close your current shell session and start a new session. Otherwise, you won’t be able to run docker and you may see permission errors.

Step 7:

Execute the following command to check either docker run correctly or not.

# docker run hello-world

Install Docker compose:

To download and install Docker compose, follow the steps below.

Step 1:

Execute the following command to download and install latest version of docker compose.

# sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

Step 2:

Now set the permissions for file using the command below.

# sudo chmod +x /usr/local/bin/docker-compose

Step 3:

Get list of started containers using the following command.

# docker container ls --all

Stop container using port 8080. To do so, get container id, replace it with 8baab990c424 below and execute the command.

# docker stop 8baab990c424

Pull and run Node.js:

In this tutorial, I will use official image of Node.js for installation on Docker. To download and install Node.js, you will need to execute the following command which will pull latest Nodejs from official docker repository.

# docker pull linode/server-node-js

Now execute the following command to run docker image.

# docker run -d -p 80:3000 linode/server-node-js

Now you can verify it by accessing your Alibaba Cloud ECS IP address or domain name pointing to that IP address. http://your_domain.com/test.htm

Setup firewalls for http, https and other required port:

You will need to open port 80 and 443. To do this, you may read the article on firewalls.

Congratulations!!…here you go…you have successfully installed Node.js for development purpose within Docker.

Leave a Reply

Your email address will not be published. Required fields are marked *