Create Docker container with both Java and Node.js

2019-06-15 13:08发布

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.

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

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

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

3条回答
Rolldiameter
2楼-- · 2019-06-15 13:51

The FROM inside your dockerfile simply tells docker from which image it should start the configuration. You can't simply concatenate multiple images together. There are already multiple container images available which offer preinstalled Java 8 and node JS. I don't want to recommend any image specifically but will direct you to docker-hub for you to go search on your own and use the container that suites your needs the best.

查看更多
相关推荐>>
3楼-- · 2019-06-15 13:59

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.

So, start with

FROM openjdk:latest

This will use the latest openjdk image, which is 8u151 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_9.x | bash - \
  && apt-get install -y nodejs \
  && curl -L https://www.npmjs.com/install.sh | sh

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

RUN npm install -g grunt grunt-cli

In total you will get the following Dockerfile:

FROM openjdk:latest

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

You may clone the Dockerfile from my gitlab repo here

查看更多
做个烂人
4楼-- · 2019-06-15 14:07

You can use single FROM per generated image. Try to use node as a base image and install java to it.

查看更多
登录 后发表回答