I'm trying to build an alpine docker image with openjdk 11. To do so, I'm starting an alpine container:

docker run -it alpine:3.9 /bin/sh

And running the following:

export JAVA_HOME=/opt/openjdk-11
export PATH=$JAVA_HOME/bin:$PATH

export JAVA_VERSION=11.0.2
export JAVA_URL=https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz
export JAVA_SHA256=99be79935354f5c0df1ad293620ea36d13f48ec3ea870c838f20c504c9668b57

set -eux; \
    wget -O /openjdk.tgz "$JAVA_URL"; \
    echo "$JAVA_SHA256 */openjdk.tgz" | sha256sum -c -; \
    mkdir -p "$JAVA_HOME"; \
    tar --extract --file /openjdk.tgz --directory "$JAVA_HOME" --strip-components 1; \
    rm /openjdk.tgz;

After that, I can confirm that a few things seem correct:

/ # ls -lah $JAVA_HOME/bin/java
+ ls -lah /opt/openjdk-11/bin/java
-rwxr-xr-x    1 668      668         8.5K Jan 18 05:20 /opt/openjdk-11/bin/java
/ # echo $PATH
+ echo /opt/openjdk-11/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
/ # which java
+ which java

But when I run java itself, I get:

/ # java -version
+ java -version
/bin/sh: java: not found

And I get kicked out of the container. Am I missing something?


The reason you're getting java: not found is likely due to dynamic linking failure. You could verify this using ldd java.

Alpine Linux is using musl-libc for its libc (standard C library) implementation, in contrast to most other Linuxes which are using glibc, GNU's C library. As a consequence, standard Linux software that is built on non-Alpine distibutions, will usually be linked against glibc and cannot be ran on Alpine, without installing a glibc compatiblity layer. So you'll need an OpenJDK 11 Alpine build, specifically.

However, unfortunately, such build is not currently available. The OpenJDK 11 page states:

The Alpine Linux build previously available on this page was removed as of JDK 11 GA. It’s not production-ready because it hasn’t been tested thoroughly enough to be considered a GA build.

The alternatives are:

  • Installing proper glibc on the Alpine container. This is a fairly easy procedure, which will allow you to run any Linux software on Alpine. However, you won't be running "native Alpine" anymore. For installation procedure, so this post.

  • Installing non-official OpenJDK 11 Alpine from an OpenJDK vendor. Specifically, Zulu OpenJDK is a very good alternative, offering thoroughly tested and verified builds, which are free and open source as well.

Futher information is available in this StackOverflow post:
Why is the Java 11 base Docker image so large? (openjdk:11-jre-slim)


As of 2/6/19, the openjdk11 package is available in Alpine repositories! It could be grabbed from the edge/community repository with:

apk --no-cache add openjdk11 --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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