Search code examples
javadockerrhinonashornalpine-linux

Alpine Linux Docker Container with jre-8 does not have Nashorn Engine


I have a docker image based on FROM anapsix/alpine-java:8_server-jre_unlimited. However, when I try

ScriptEngine scriptEngine = new ScriptEngineManager().getEngineByName("nashorn");

scriptEngine is null. I tried to get the default engine with :

ScriptEngine scriptEngine = new ScriptEngineManager().getEngineByName("js");

and it returns null as well, where as since it is java8, my understanding was, it should return jdk.nashorn.api.scripting.NashornScriptEngine

Is this because jre-8 here is a lighter version for Alpine? Should I install full JDK to solve this problem?

Reference : http://blog.takipi.com/lean-mean-java-virtual-machine-making-your-docker-7x-lighter-with-alpine-linux/


Solution

  • Although installing openjdk8 would solve the problem, this is not the right approach. Advantage of using Alpine is to create a minimal (size) docker image, which means it has only the minimum required Java components. This is why Scripting API (Nashorn) has being removed from the image. Therefore, if we need specific Java functionality such as Scripting API, we have to switch to a full JDK version without using Alpine, or create a custom base image similar to Alpine, but with Scripting API components (for this case).