Detailed process of docker installation, image creation, loading and running nodejs program

Time:2021-11-30

System environment: win7

1、 Install docker

Download and install docker toolbox from docker’s official website and install

After installation, three icons appear:

2、 Create docker image

Docker can dynamically build an image through the contents of the dockerfile file.

Dockerfile is a text file containing all commands for creating an image. You can use docker build command to build an image according to its contents.

For example, create a docker image of the nodejs program:

1. Create a new directory and initialize NPM init in CMD.

2. Create a demo program as follows:

Note: if a formal product or project is packaged and released with docker, such as the function code in the above example, in order to prevent the source code from being extracted and causing source code leakage, the nodejs code can be used before making an imageJShamanPerform JS code obfuscation encryption.

Create an empty file named dockerfile, and fill in the following contents:


FROM node:boron
 
# Create app directory
WORKDIR /app
 
# Install app dependencies
COPY package.json .
# For [email protected] 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 mirror

Start docker QuickStart terminal and run the command

docker build -t nodedemo .

(. Indicates to create to the current directory)

3、 Run mirror


docker run -p 3000:3000 -d nodedemo

Then you can access the nodejs service.

The above is the details of docker installation, creating image, loading and running nodejs program. For more information about docker nodejs running program, please pay attention to other related articles of developeppaer!