The nodejs project is deployed to the docker container to run

The nodejs project is deployed to the docker container to run

1. Create Dockerfilefiles in the root directory of the program

FROM node:11.2.0  #  node 
WORKDIR/apis/nodeAppServer  # docker 
COPY ./apis/nodeAppServer   #  docker 
RUN npm install         #  linux 
CMD [ "node","server" ] #  linux node 
 

Directory Structure:

2. Put it onlinux

Build mirror

docker build -t nodeAppServer .
 

Check the image after the build is successfuldocker images

[root@localhost nodeAppServer]# docker images
REPOSITORY                             TAG                 IMAGE ID            CREATED             SIZE
nodeAppServer                  latest              6c5d3ccf3af0        12 seconds ago      900 MB
 

3. Run the dockercontainer

docker run -d --name nodeAppServer -p 8068:8068 nodeAppServer
 

docker ps View the running container

docker logs View container error log

[root@localhost nodeAppServer]# docker ps
CONTAINER ID        IMAGE                   COMMAND             CREATED             STATUS              PORTS                    NAMES
83130c5100a8        nodeAppServer   "node server"       2 seconds ago       Up 1 second         0.0.0.0:8068->8068/tcp   nodeAppServer

 

Access application

Pay attention to opening the firewall port, firewall-cmd --zone=public --add-port=8068/tcp --permanent firewall-cmd --reload

[root@localhost nodeAppServer]# curl http://localhost:8068/project/yourparams