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

Share 9 Linux Shell Scripting Tips for Practice and Interviews

Precautions 1) Add interpreter at the beginning: ...

Have you carefully understood Tags How it is defined How to use

Preface : Today I was asked, "Have you carefu...

Example of using Nginx to implement port forwarding TCP proxy

Table of contents Demand Background Why use Nginx...

Native js to realize a simple snake game

This article shares the specific code of js to im...

Tutorial diagram of installing mysql8.0.18 under linux (Centos7)

1 Get the installation resource package mysql-8.0...

Do you know what are the ways to jump routes in Vue?

Table of contents The first method: router-link (...

What to do if you forget your password in MySQL 5.7.17

1. Add skip-grant-tables to the my.ini file and r...

Solution to the blank page after vue.js packaged project

I believe that many partners who have just come i...

Will the index be used in the MySQL query condition?

When an employer asks you whether an index will b...

Detailed analysis of the blocking problem of js and css

Table of contents DOMContentLoaded and load What ...

Learn more about MySQL indexes

1. Indexing principle Indexes are used to quickly...

Vue Element-ui table realizes tree structure table

This article shares the specific code of Element-...

Detailed explanation of the usage of MySQL data type DECIMAL

MySQL DECIMAL data type is used to store exact nu...