Statement: due to the different needs of each user in each company, the problems I encounter do not represent all of them. I am the first time to contact docker. Don't spray if you don't like it.

Due to the business requirements of the company, the nodejs environment needs to be deployed in the container, connected with the previous ng,mysql,redis, etc., and finally downloaded the files in the database from the web interface.

I. use wget to download nodejs tar package from the official website (provided that the container can connect to the Internet and has wget tools)

> wget https://nodejs.org/dist/v12.13.0/node-v12.13.0-linux-x64.tar.xz

2. Extract the folder with the same name

tar -xf node-v12.13.0-linux-x64.tar.xz

3. Configure environment variables

vim .bash_profile(I configure local variables here,vim /etc/profile global variable)

export NODE_HOME=/nodejs Route

export PATH=$PATH:$NODE_HOME/bin 

export NODE_PATH=$NODE_HOME/lib/node_modules

IV. save to exit and load the configuration file, otherwise it will not take effect.

[root@60c8342a1e87 ~]# source  /etc/profile

[root@60c8342a1e87 ~]# node -v  
v12.13.0        Explanation at this time nodejs Successful installation

[root@60c8342a1e87 ~]# npm i installation dependency package

[root@60c8342a1e87 ~]# npm run start

[root@f76f71c72da2 config]# curl http://localhost:7001
hi, welcome to duyansoft     Startup success

This is a manual deployment in the container. Write a Dockerfile to automatically generate a nodejs image. First, demonstrate the error:

[root@izbp158xjb4poadz7piz7tz nodejs]# cat Dockerfile
From centos
RUN yum -y install wget 
WORKDIR /root
RUN wget https://nodejs.org/dist/v12.13.0/node-v12.13.0-linux-x64.tar.xz
RUN tar -xf node-v12.13.0-linux-x64.tar.xz
ADD profile /etc/      #Replace profile in container according to manual deployment
WORKDIR /usr/local/duyansoft/service/  #Custom Catalog
ADD anmiLocalNode.tar.gz .     #Code
RUN mv anmiLocalNode-*  anmiLocalNode #Rename
#RUN /root/node-v12.13.0-linux/bin/npm i    #This is because the npm command has been unable to be found. It runs directly in absolute path. Is it visible or not?
WORKDIR  anmiLocalNode/config/ 
ADD config.default.js .     #Some configurations have been modified to replace the original configuration
RUN source /etc/profile   #Load global variables
#WORKDIR /root/node-v12.13.0-linux-x64/bin
RUN npm i     
ENTRYPOINT  npm run start &&  tail -f /dev/random

The command can't be found. Think about the reason. There's no problem with manual deployment. Why can't you find it when you arrive? The first guess is the problem of environmental variables.

Write Dockerfile correctly

[root@izbp158xjb4poadz7piz7tz nodejs]# cat Dockerfile 
From centos
RUN yum -y install wget 
WORKDIR /root
RUN wget https://nodejs.org/dist/v12.13.0/node-v12.13.0-linux-x64.tar.xz
RUN tar -xf node-v12.13.0-linux-x64.tar.xz
ENV NODE_HOME=/root/node-v12.13.0-linux-x64
ENV PATH=$PATH:$NODE_HOME/bin
ENV NODE_PATH=$NODE_HOME/lib/node_modules   #Using ENV for global variables written in files, you can implement global in containers
RUN mkdir -p /usr/local/duyansoft/service/
WORKDIR /usr/local/duyansoft/service/
ADD anmiLocalNode.tar.gz .
RUN mv anmiLocalNode-*  anmiLocalNode
WORKDIR  anmiLocalNode/config/ 
ADD config.default.js .
RUN npm i 
ENTRYPOINT  npm run start &&  tail -f /dev/random