I'm trying to build an Alpine Linux image that contains OpenJDK. The Java runtime (java
) is installed, but the Java compiler (javac
) isn't. I expect the compiler to come with OpenJDK, like how it is when installing via apt
or yum
.
FROM alpine:latest
RUN apk update
RUN apk add bash openjdk8
RUN java -version
RUN javac --version
When building the Dockerfile, the following error is returned:
The command '/bin/sh -c javac -version' returned a non-zero code: 127
How can I have the Java compiler available on Alpine?
Try this:
FROM alpine:latest
USER root
RUN apk update
RUN apk fetch openjdk8
RUN apk add openjdk8
ENV JAVA_HOME=/usr/lib/jvm/java-1.8-openjdk
ENV PATH="$JAVA_HOME/bin:${PATH}"
RUN java -version
RUN javac -version
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With