Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Docker container with both Java and Node.js

Tags:

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.

like image 256
Alexander Mills Avatar asked May 03 '17 20:05

Alexander Mills


People also ask

Can a Docker container have multiple applications?

It's ok to have multiple processes, but to get the most benefit out of Docker, avoid one container being responsible for multiple aspects of your overall application. You can connect multiple containers using user-defined networks and shared volumes.

Can one Docker image have multiple containers?

Using the docker-compose CLI command, you can create and start one or more containers for each dependency with a single command (docker-compose up).

Can an application developer run multiple containers through a single container?

Docker Compose is a tool that helps us overcome this problem and efficiently handle multiple containers at once. Also used to manage several containers at the same time for the same application. This tool can become very powerful and allow you to deploy applications with complex architectures very quickly.


1 Answers

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

like image 85
Alex Karshin Avatar answered Sep 21 '22 15:09

Alex Karshin