0

I am trying to dockerize my NodeJs & Express API . In my API iam using https://www.npmjs.com/package/compile-run package to compile and run C, Cpp,Java,JavaScript(Node.js env), Python languages. This package requires all 5 compilers(gcc,g++,nodejs,python3,javac) installed on the server. If any compiler misses, it throws error.

In my local(undockerized) the API is working completely fine on both windows & ubuntu(As I have installed compilers on them).

I am trying to replicate the same on my docker image. But I am stuck.

Look at my Dockerfile:

FROM node:12
WORKDIR /app
COPY package.json /app
RUN npm install
COPY . /app
CMD ["npm","start"]

I think node-12 image comes along with gcc, g++,python3 and nodejs(obviously). But the issue is with java. I am not able to compile java code.

so I tried it this way

FROM node:12
RUN apt-get -y install default-jre
# RUN java -version
RUN apt -y install default-jre
RUN apt install openjdk-11-jre-headless
RUN java -version

WORKDIR /app


COPY package.json /app
RUN npm install
COPY . /app
CMD ["npm","start"]

But I am not able to install open-jdk or open-jre with apt/apt-get. What is the right way to configure docker?

This is my nodeJS API repository https://github.com/yogendramaarisetty/online-compiler-api

7
  • 1
    Could multistage builds Help ?
    – Marged
    Aug 22, 2020 at 19:29
  • No I have no idea Aug 22, 2020 at 19:56
  • 1
    You could use one stage for each language you need instead of taking one and adding more languages
    – Marged
    Aug 22, 2020 at 19:58
  • Can you answer with more detailed implementation. I am new to docker. Aug 22, 2020 at 19:59
  • 1
    @DavidMaze OP doesn't want multiple containers. OP wants to host an online compiler. The specifics are undefined here, but I assume something like Matt Godbolt's Compiler Explorer. Aug 22, 2020 at 22:48

1 Answer 1

7

First you must update the package list with apt-get update, then you can install openjdk-8. openjdk-11 isn't available with that distribution of node. I used docker run -it node:12 /bin/bash to see what there was,

FROM node:12
RUN apt-get update && apt-get install -y openjdk-8-jdk

For example,

$ cat Dockerfile                                         
FROM node:12
RUN apt-get update && apt-get install -y openjdk-8-jdk
$ docker build --tag mynode:1.0 .
$ docker run -it mynode:1.0 /bin/bash                                    
root@d70858199dd1:/# java -version
openjdk version "1.8.0_265"
OpenJDK Runtime Environment (build 1.8.0_265-8u265-b01-0+deb9u1-b01)
OpenJDK 64-Bit Server VM (build 25.265-b01, mixed mode)
root@d70858199dd1:/# javac -version
javac 1.8.0_265
root@d70858199dd1:/#

If you really do need Java 11, there are multiple ways and places to get openjdk-11. One is bell-sw. For example,

$ cat Dockerfile
FROM node:12
RUN apt-get update && apt-get install -y libasound2 libxtst6
RUN wget https://download.bell-sw.com/java/11.0.7+10/bellsoft-jdk11.0.7+10-linux-amd64.deb && \
    apt install ./bellsoft-jdk11.0.7+10-linux-amd64.deb
$ docker build --tag mynode:1.1 .
$ docker run -it mynode:1.1 /bin/bash
root@37771ce98727:/# java -version
openjdk version "11.0.7" 2020-04-14 LTS
OpenJDK Runtime Environment (build 11.0.7+10-LTS)
OpenJDK 64-Bit Server VM (build 11.0.7+10-LTS, mixed mode)
root@37771ce98727:/# javac -version
javac 11.0.7
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.