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
/opt/openjdk-11/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
/ # which java
+ which java
/opt/openjdk-11/bin/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?