简体   繁体   English

如何在 Docker 上安装 nodejs?(Windows 容器)

[英]How to install nodejs on Docker?(Windows Container)

I've just created docker image of my spring boot application and I've implemented some functions that require nodejs.我刚刚创建了 spring 启动应用程序的 docker 映像,并且我实现了一些需要 nodejs 的功能。 I searched and tried various ways but could not figure it out how to make node command could be run on Docker.我搜索并尝试了各种方法,但无法弄清楚如何使节点命令可以在 Docker 上运行。

I've pulled node into Docker.我已将节点拉入 Docker。

docker pull node

Here is my Dockerfile这是我的 Dockerfile

FROM openjdk:8-jre 
EXPOSE 8080
ADD target/testdemo-1.0.0-BUILD-SNAPSHOT.war /testdemo-1.0.0-BUILD-SNAPSHOT.war
ENTRYPOINT ["java", "-jar", "/testdemo-1.1.0-BUILD-SNAPSHOT.war"]

Because of some memory issue, I've had a problem switching to Linux Container, so please tell me how to install nodejs on Windows container.由于一些 memory 问题,我在切换到 Linux 容器时遇到了问题,所以请告诉我如何在 Windows 容器上安装 nodejs。 I've just started Docker so please go easy on me.我刚刚开始 Docker 所以请 go 对我轻松一点。

Thank you in advance.先感谢您。

EDIT I added this line to my Dockerfile编辑我将此行添加到我的 Dockerfile

RUN msiexec.exe /a https://nodejs.org/dist/v12.18.3/node-v12.18.3-x64.msi /quiet

Whild building a docker image I get this error.在构建 docker 图像时,我收到此错误。

Step 2/6 : RUN msiexec.exe /a https://nodejs.org/dist/v12.18.3/node-v12.18.3-x64.msi /quiet
 ---> Running in 3b025a7238f2
T h i s   i n s t a l l a t i o n   p a c k a g e   c o u l d   n o t   b e   o p e n e d .     
V e r i f y   t h a t   t h e   p a c k a g e   e x i s t s   a n d   t h a t   y o u   c a n   a c c e s s   i t ,  
 o r   c o n t a c t   t h e   a p p l i c a t i o n   v e n d o r   t o   v e

Building a docker image is successfully done after all but I still get "'node' is not recognized as an internal or an external command, ..." error if my spring boot application trying to use node command.构建 docker 映像毕竟已成功完成,但如果我的 spring 引导应用程序尝试使用节点命令,我仍然会得到“'node' is not known as an internal or an external command, ...”错误。

While Marek's answer will probably work;虽然马雷克的答案可能会奏效; please make sure you use the latest version of node, since node 8 is officially EOL.请确保您使用最新版本的节点,因为节点 8 已正式 EOL。

You can also add the installation command to your Dockerfile, this way your application actually works upon starting the docker container:您还可以将安装命令添加到您的 Dockerfile,这样您的应用程序实际上在启动 docker 容器时就可以工作:

FROM openjdk:8-jre 
RUN msiexec.exe /a https://nodejs.org/dist/v12.18.3/node-v12.18.3-x64.msi /quiet
EXPOSE 8080
ADD target/testdemo-1.0.0-BUILD-SNAPSHOT.war /testdemo-1.0.0-BUILD-SNAPSHOT.war
ENTRYPOINT ["java", "-jar", "/testdemo-1.1.0-BUILD-SNAPSHOT.war"]

You haven't pulled node into Docker .您尚未将节点拉入 Docker By doing docker pull node you actually download official node image from dockerhub ( https://hub.docker.com/_/node/ ).通过执行docker pull node ,您实际上是从 dockerhub 下载官方节点映像( https://hub.docker.com/_/node/ )。

What you actually have to do is actually pull node within your docker container.您实际上要做的实际上是在 docker 容器中拉取节点。 Simplest approach how to do it from command line once you are in your windows container:进入 windows 容器后,如何从命令行执行此操作的最简单方法:

msiexec.exe /a https://nodejs.org/dist/v8.3.0/node-v8.3.0-x64.msi /quiet

Let me know if it worked.让我知道它是否有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM