Java version updated on package installation

I have issue with updated symlink on java after maven installation. I use simple docker file:

FROM java:8
RUN ["java", "-version"]
RUN apt-get update && apt-get install -y maven && rm -rf /var/lib/apt/lists/*
RUN ["java", "-version"]
CMD ["java", "-version"]

During build I’ve got next log:

  • nfs volume mount to mysql docker container inside a ubuntu virtualbox fail
  • Running rust on Docker: Empty reply from server
  • connection between curator4 and elasticsearch running into two containers
  • Can't connect to mongodb in the docker container
  • Docker Compose and execute command on starting container
  • Unable to start TensorFlow within Docker, on Windows
  • Step 0 : FROM java:8
     ---> 4cd29d33e3f4
    Step 1 : RUN java -version
     ---> Running in 1c528620f318
    openjdk version "1.8.0_66-internal"
    OpenJDK Runtime Environment (build 1.8.0_66-internal-b01)
    OpenJDK 64-Bit Server VM (build 25.66-b01, mixed mode)
     ---> d25e96460a85
    Removing intermediate container 1c528620f318
    Step 2 : RUN apt-get update && apt-get install -y maven && rm -rf /var/lib/apt/lists/*
    ....installation logs....
    Setting up openjdk-7-jre-headless:amd64 (7u79-2.5.6-1~deb8u1) ...
    update-alternatives: using /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/rmid to provide /usr/bin/rmid (rmid) in auto mode
    update-alternatives: using /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java to provide /usr/bin/java (java) in auto mode
    

    So as you can see maven brings java 7 and update-alternatives makes it default version.
    So I have several questions:

    1. Why maven requires java 7 while java 8 already installed? Why dependencies are not transparent?
    2. Is it possible to not install java 7 and use java 8 instead?
    3. If not, what is the best way to set java 8 as default? Remove java 7, configure update-alternatives or something else?

  • Docker Windows - Looking for Ubuntu command in bash location
  • Symfony2 app always has a 3 second wait between kernel.request and kernel.controller
  • Docker Error : Cannot use --lxc-conf with execdriver: native-0.2
  • Rename a project by keeping containers
  • What directory does a Docker build start in?
  • Docker: container can't find domain on private network
  • 2 Solutions collect form web for “Java version updated on package installation”

    I think all this is distro specific.

    As in: In your chosen distro (Ubuntu?) the particular maven package that you are installing has a dependency to OpenJDK 7 (and not 8).

    I see two options for a Java 8 / maven setup:

    • install maven from a tgz
    • create your own maven package

    I tried out your setup see

    https://github.com/BITPlan/docker-stackoverflowanswers/tree/master/33324470

    and by running:

    ./build
    ./run
    

    i entered a bash to see what the situation is:

    Java Version

    root@940c282bd6ad:/# java -version
    java version "1.7.0_79"
    OpenJDK Runtime Environment (IcedTea 2.5.6) (7u79-2.5.6-1~deb8u1)
    OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)
    

    So by default this distro uses an OpenJDK 1.7

    Maven Version

    root@940c282bd6ad:/# mvn -version
    Apache Maven 3.0.5
    Maven home: /usr/share/maven
    Java version: 1.8.0_66-internal, vendor: Oracle Corporation
    Java home: /usr/lib/jvm/java-8-openjdk-amd64/jre
    Default locale: en, platform encoding: UTF-8
    OS name: "linux", version: "4.1.10-boot2docker", arch: "amd64", family: "unix"
    

    The maven uses Oracle Java 1.8

    Now you have got multiple options

    Select another default java
    as outlined in

    https://askubuntu.com/questions/272187/setting-jdk-7-as-default

    root@940c282bd6ad:/# update-alternatives --config java
    There are 2 choices for the alternative java (providing /usr/bin/java).
    
      Selection    Path                                            Priority   Status
    ------------------------------------------------------------
    * 0            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      auto mode
      1            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      manual mode
      2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1069      manual mode
    

    Switch the default java version as outlined in:

    https://askubuntu.com/questions/491778/switch-to-oracle-java-jdk-in-14-04

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.