Create a Docker container with Java and Node.js

I'm not sure why I expected this to work:

# Dockerfile FROM node:6 FROM java:8 

but actually it doesn’t work - it seems that the first command is being ignored, and the second command is working.

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

Ultimately, the problem I'm trying to solve is that I get an ENOENT error when starting Selenium Webdriver -

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

And right now, I assume that Java is not installed in the container.

+5
source share
3 answers

You can use a single FROM for the generated image. Try using node as the base image and install java for it.

+3
source

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

So start with

 FROM openjdk:latest 

At this time, the latest openjdk image, which is 8u151 , will be used. Then install node and other dependencies you may 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, so this might come in handy.

 RUN npm install -g grunt grunt-cli 

In total, you will receive the following Docker file:

 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 can clone the Docker file from my github repo here

+7
source

FROM inside your docker file simply tells the docker which image it should start configuring from. You cannot just combine multiple images together. There are already several container images that offer pre-installed Java 8 and node JS. I don’t want to recommend any image specifically, but it will direct you to the docker-hub so that you can independently search and use the container that best suits your needs.

+1
source

All Articles