Detailed process of installing Docker, creating images, loading and running NodeJS programs

Detailed process of installing Docker, creating images, loading and running NodeJS programs

System environment: Windows 7

1. Install Docker

Download and install docker-ToolBox from the Docker official website and install

After the installation is complete, three icons appear:

2. Create a Docker image

Docker can automatically build images based on the contents of the Dockerfile file.

Dockerfile is a text file that contains all the commands for creating an image. Use the docker build command to build an image based on its content.

Example, create a Docker image of a NodeJS program:

1. Create a new directory and initialize it with npm init in cmd.

2. Create a demo program with the following contents:

Note: If a formal product or project is packaged and released with Docker, such as the functional code in the above example, in order to prevent the source code from being extracted and leaked, the NodeJS code can be obfuscated and encrypted with JShaman before making the image.

Create an empty file named Dockerfile and fill in the following content:

FROM node:boron
 
# Create app directory
WORKDIR /app
 
# Install app dependencies
COPY package.json .
# For npm@5 or later, copy package-lock.json as well
# COPY package.json package-lock.json ./
 
RUN npm install
 
# Bundle app source
COPY . .
 
EXPOSE 3000
CMD [ "node", "demo.js" ]

3. Create an image

Start the Docker Quickstart Terminal and run the command

docker build -t nodedemo .

(. means creating in the current directory)

3. Run the image

docker run -p 3000:3000 -d nodedemo

Then you can access the nodejs service.

The above is the details of installing Docker, creating images, loading and running NodeJS programs. For more information about docker NodeJS running programs, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Detailed explanation of JavaScript operation mechanism and a brief discussion on Event Loop
  • Learn the operating mechanism of jsBridge in one article
  • Let you understand the working principle of JavaScript
  • How to run JavaScript in Jupyter Notebook
  • Solve the problem that running js files in the node terminal does not support ES6 syntax
  • Tutorial on compiling and running HTML, CSS and JS files in Visual Studio Code
  • Example of running JavaScript with Golang
  • Front-end JavaScript operation principle

<<:  Solve the problem of Navicat for Mysql connection error 1251 (connection failed)

>>:  12 Laws of Web Design for Clean Code [Graphic]

Recommend

How to deploy MySQL and Redis services using Docker

Table of contents How to deploy MySQL service usi...

How to build your own Nexus private server in Linux

This article describes how to build a Nexus priva...

Jmeter connects to the database process diagram

1. Download the MySQL jdbc driver (mysql-connecto...

How to start multiple MySQL instances in CentOS 7.0 (mysql-5.7.21)

Configuration Instructions Linux system: CentOS-7...

Docker network principles and detailed analysis of custom networks

Docker virtualizes a bridge on the host machine. ...

Detailed explanation of display modes in CSS tags

Label display mode (important) div and span tags ...

Detailed explanation of NodeJS modularity

Table of contents 1. Introduction 2. Main text 2....

MySQL Community Server 5.7.19 Installation Guide (Detailed)

MySQL official website zip file download link htt...

Javascript closure usage scenario principle detailed

Table of contents 1. Closure 2. Closure usage sce...

JS implements jQuery's append function

Table of contents Show Me The Code Test the effec...

Example of compiling LNMP in Docker container

Table of contents 1. Project Description 2. Nginx...

Mybatis statistics of the execution time of each SQL statement

background I am often asked about database transa...

Linux CentOS 6.5 Uninstall, tar and install MySQL tutorial

Uninstall the system-provided MySQL 1. Check whet...

Detailed steps to install MySQL 5.7 via YUM on CentOS7

1. Go to the location where you want to store the...