本文介绍了使用Java和Node.js创建Docker容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么我会这样做:

I am not sure why I expected this to work:

 # Dockerfile
 FROM node:6
 FROM java:8

但它没有真正的工作 - 看起来像第一个命令被忽略,和第二个命令工作。

but it doesn't really work - looks like the first command is ignored, and second command works.

有没有直接的方法来在Docker容器中安装Node.js和Java?

Is there a straightforward way to install both Node.js and Java in a Docker container?

最终我想要解决的问题是,当运行Selenium Webdriver时,我收到一个ENOENT错误 -

Ultimately the problem I am trying to solve is that I am getting an ENOENT error when running Selenium Webdriver -

[20:38:50] W/start - Selenium Standalone server encountered an error: Error: spawn java ENOENT

现在我假设是因为Java没有安装在容器中。

And right now I assume it's because Java is not installed in the container.

推荐答案

最好的方法是使用java (正式已弃用,建议您使用 openjdk image)并安装节点。

The best way for you is to take java (which is officially deprecated and it suggests you use openjdk image) and install node in it.

所以,开始与

FROM openjdk:latest

这将使用最新的openjdk映像,它是 8u121 此时。然后安装节点和您可能需要的其他依赖项:

This will use the latest openjdk image, which is 8u121 at this time. Then install node and other dependencies you might need:

RUN apt-get install -y curl
  && curl -sL https://deb.nodesource.com/setup_7.x | bash -
  && apt-get install -y nodejs
  && curl -L https://www.npmjs.com/install.sh | sh

你可能想安装以后的咕噜声,所以这也可能会派上用场。 / p>

You might want to install things like grunt afterwards, so this might come in handy as well.

RUN npm install -g grunt grunt-cli

总共有以下Docker文件:

In total you will get the following Dockerfile:

FROM openjdk:latest

RUN apt-get install -y curl
  && curl -sL https://deb.nodesource.com/setup_7.x | bash -
  && apt-get install -y nodejs
  && curl -L https://www.npmjs.com/install.sh | sh
RUN npm install -g grunt grunt-cli

这篇关于使用Java和Node.js创建Docker容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 20:31