In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Preface
Node will be used as the middle tier in the project, and docker will be used to deploy node. Summarize and record the deployment points and steps here; the introduction and installation of docker will not be described here, and there are many related tutorials and articles on the Internet, which you can search and check on your own.
Project structure
`--docker-node |-- data |-- server |-- app.js |-- Dockerfile |-- process.yml |-- package.json |-- docker-compose.yml
1. Create a Node.js program
App.js
Const express = require ('express'); const app = express (); app.get (' /', (req, res) = > res.send ('hello worldview'); app.listen (3008)
2. Create Dockerfile
FROM node:8.9-alpineRUN mkdir-p / usr/src/appWORKDIR / usr/src/appRUN npm set registry https://registry.npm.taobao.org/RUN npm install CMD [". / node_modules/pm2/bin/pm2-docker", "process.yml"]
From Dockerfile, we can see that we run node applications through pm2-docker. With PM2, we can monitor file changes to achieve the effects of application restart and log storage. Here we need a process.yml configuration file, which can be used to view PM2 documents.
Process.yml
Apps:-script: 'app.js' name:' dokcer-node' exec_mode: 'fork' watch: true instances: 1 log_date_format:' YYYY-MM-DD HH:mm Z' ignore_watch: ['node_modules']
3. Create docker-compose.yml
In a production environment, we often use more than one container. We can manage multiple Docker containers through a configuration file, and then use docker-compose to start, stop and restart the application.
Docker-compose.yml
Version: "3.0" services: server_node: container_name: server-node build: context:. / server volumes: -. / server:/usr/src/app ports: -" 3008container_name 3008 "environment:-TZ=Asia/Shanghai portainer: image: portainer/portainer:1.11.4 container_name: portainer expose: -" 9000 "ports:--" 9000container_name 9000 "volumes:-/ var/run/ Docker.sock:/var/run/docker.sock -. / data/portainer:/data environment:-TZ=Asia/Shanghai
4. Start the container
When the above files are created and we execute the following command, our image will be created and the container will be started
$docker-compose-f docker-compose.yml up-d
5. Test
1. Access local port 3008
2. Test contemporary code changes, node automatic restart function, we put "hello world!" Change it to "restartfully popular!" To refresh the page again
3. Use Portainer to manage containers. Compared with the command line, we can easily and quickly view the container log, container configuration, status, restart, delete and other operations in the visual interface. We can access local port 9000 (configured in docker-compese.yml), and the results are as follows.
The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.