Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 使用docker安装nodejs_Node.js_Centos_Docker - Fatal编程技术网

Node.js 使用docker安装nodejs

Node.js 使用docker安装nodejs,node.js,centos,docker,Node.js,Centos,Docker,我尝试了以下方法将节点安装到centos机箱中,但在其到达时出现错误。/configure Step 6 : RUN tar -zxf node-v0.10.28-linux-x64.tar.gz ---> Running in ebc71472544d ---> c97289348900 Removing intermediate container ebc71472544d Step 7 : RUN cd /node-v0.10.28-linux-x64 ---> Runn

我尝试了以下方法将节点安装到centos机箱中,但在其到达时出现错误。/configure

Step 6 : RUN tar -zxf node-v0.10.28-linux-x64.tar.gz
---> Running in ebc71472544d
---> c97289348900
Removing intermediate container ebc71472544d
Step 7 : RUN cd /node-v0.10.28-linux-x64
---> Running in 3470f862c586
---> 1771d01a5da0
Removing intermediate container 3470f862c586
Step 8 : RUN ./configure
 ---> Running in 16a811766136
/bin/sh: ./configure: No such file or directory
我的Dockerfile

#Install NodeJS
RUN cd /usr/src
RUN wget http://nodejs.org/dist/v0.10.28/node-v0.10.28-linux-x64.tar.gz
RUN tar -zxf node-v0.10.28-linux-x64.tar.gz
RUN cd /node-v0.10.28-linux-x64
RUN ./configure
RUN make &&
RUN make install

我使用Dockerfile将节点安装到centos的方法正确吗?

我假设这不是整个Dockerfile,对吗?否则,您至少会从中丢失一个

尝试这样更改最后4行:

RUN cd /node-v0.10.28-linux-x64 && ./configure
RUN cd /node-v0.10.28-linux-x64 && make
RUN cd /node-v0.10.28-linux-x64 && make install
还是像这样

RUN cd /node-v0.10.28-linux-x64 && ./configure && make && make install
据我所知,docker正在将每个
RUN
命令作为一个单独的shell运行,因此在接下来的命令中不会记住仅仅更改目录

下面是一个示例Docker文件来测试这一点:

FROM ubuntu

RUN cd /etc
RUN pwd
以下是构建日志:

Step 0 : FROM ubuntu
 ---> 99ec81b80c55
Step 1 : RUN cd /etc
 ---> Running in a4c25ee340a8
 ---> 82ad93bdd18c
Removing intermediate container a4c25ee340a8
Step 2 : RUN pwd
 ---> Running in f535178df40c
/
 ---> 495c68757268
[编辑]

另一个选项是使用,如下所示:

#Install NodeJS
WORKDIR /usr/src
ADD http://nodejs.org/dist/v0.10.28/node-v0.10.28-linux-x64.tar.gz .
RUN tar -zxf node-v0.10.28-linux-x64.tar.gz
WORKDIR node-v0.10.28-linux-x64
RUN ./configure
RUN make &&
RUN make install

我使用nvm的解决方案:

RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
RUN source $HOME/.bashrc && nvm install 12.14.1

RUN ln -s $HOME/.nvm/versions/node/v12.14.1/bin/node /usr/bin/node
RUN ln -s $HOME/.nvm/versions/node/v12.14.1/bin/npm /usr/bin/npm

RUN node -v
RUN npm -v