Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What do you need to pay attention to when installing nodejs environment in docker container?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

What this article shares with you is about what you need to pay attention to when installing the nodejs environment for docker containers. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

Disclaimer: due to the inconsistent needs of each company and each user, the problems I encounter do not represent all. I am also the first time to contact docker, the boss does not like to spray. Due to the company's business needs, the nodejs environment needs to be deployed in a container, connected to the previous ng,mysql,redis, etc., and finally download the files in the database from the web interface. First, download the nodejs tar package from the official website with wget (provided that the container can be connected to the public network and have wget tools) > wget https://nodejs.org/dist/v12.13.0/node-v12.13.0-linux-x64.tar.xz. Second, decompress to get a folder with the same name.

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

Configure the environment variable vim. Bash _ profile (I configure local variables here, vim / etc/profile global variables) export NODE_HOME=/nodejs path export PATH=$PATH:$NODE_HOME/bin export NODE_PATH=$NODE_HOME/lib/node_ modules IV, save exit, and load the configuration file Otherwise, it will not take effect [root@60c8342a1e87 ~] # source / etc/profile [root@60c8342a1e87 ~] # node-v v12.13.0. This means that nodejs is installed successfully [root@60c8342a1e87 ~] # npm I installs the dependency package [root@60c8342a1e87 ~] # npm run start starts [root@f76f71c72da2 config] # curl http://localhost:7001hi, welcome to duyansoft starts successfully. The following is a manual deployment in the container. Write Dockerfile to automatically generate nodejs images. First error demonstration: [root@izbp158xjb4poadz7piz7tz nodejs] # cat DockerfileFrom centosRUN yum-y install wget WORKDIR / rootRUN wget https://nodejs.org/dist/v12.13.0/node-v12.13.0-linux-x64.tar.xzRUN tar-xf node-v12.13.0-linux-x64.tar.xzADD profile / etc/ # customize the directory ADD anmiLocalNode.tar.gz according to manual deployment to replace the profileWORKDIR / usr/local/duyansoft/service/ # in the container. # Code RUN mv anmiLocalNode-* anmiLocalNode # renamed # RUN / root/node-v12.13.0-linux/bin/npm I # here is because the npm command has been unable to find fire, run directly in the absolute path, visible or not WORKDIR anmiLocalNode/config/ ADD config.default.js. # modified some configurations to replace the original configuration RUN source / etc/profile # load the global variable # WORKDIR / root/node-v12.13.0-linux-x64/binRUN npm i ENTRYPOINT npm run start & & tail-f / dev/random

The command can not be found, think about the reason, manual deployment is no problem, why you can't find it as soon as you get there. First of all, the guess is that the problem of environment variables is to correctly write the Dockerfile [root @ izbp158xjb4poadz7piz7tz nodejs] # cat Dockerfile From centosRUN yum-y install wget WORKDIR / rootRUN wget https://nodejs.org/dist/v12.13.0/node-v12.13.0-linux-x64.tar.xzRUN tar-xf node-v12.13.0-linux-x64.tar.xzENV NODE_HOME=/root/node-v12.13.0-linux-x64ENV PATH=$PATH:$NODE_HOME/binENV NODE_PATH=$NODE_HOME/lib/node_modules. # use ENV for global variables to be written in the file The global RUN mkdir-p / usr/local/duyansoft/service/WORKDIR / usr/local/duyansoft/service/ADD anmiLocalNode.tar.gz .Run mv anmiLocalNode-* anmiLocalNodeWORKDIR anmiLocalNode/config/ ADD config.default.js .Run npm i ENTRYPOINT npm run start & & tail-f / dev/random above is what you need to pay attention to when installing the nodejs environment in the container. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report