Docker: different java versions in interactive and non-interactive modes

1k views Asked by At

Here is my Dockerfile

FROM ubuntu:20.04

# Install java 8 with apt-get
RUN apt-get update -qq && apt-get install -yqq openjdk-8-jdk

# Install java 11 with sdkman
RUN apt-get install -yqq curl unzip zip
RUN curl -s "https://get.sdkman.io" | bash
RUN /bin/bash -c "source /root/.sdkman/bin/sdkman-init.sh; sdk install java 11.0.12-open"

# Print java version
RUN java -version

RUN java -version says java 8

In interactive mode (docker run --rm -it <image-id>), it says java 11

Using RUN /bin/bash -c "source /root/.sdkman/bin/sdkman-init.sh; java -version" in the Dockerfile gives java 11

Why ? What could explain the difference between those behaviors ? Installing java 11 with apt-get doesn't give this problem, the default java version becomes 11 no matter what.

0

There are 0 answers