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:

  • Best way to have Jenkins “update” a running docker container when the image has been updated
  • DRY Config for Docker build and App
  • Docker-based Ambari 1.7 cluster install wizard repo URL dead (404) while 'Running setup agent script'
  • Docker php excel error (php://output) i/o stream
  • How use my docker-compose configuration with gitlab CI
  • Docker DNS Error
  • 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 unable to connect AWS EC2 cloud
  • second ssh session can not connect to docker host
  • Error using Django with Docker - “Can't connect to MySQL server on '' (111)”)
  • How to use pipes(ioredirection) in Dockerfile RUN?
  • How to load db2 dump data from the one db(remotly installed) to docker based db
  • Command to Copy/share jmeter master container results (Docker) generated in by running the script in non-gui mode to EC2 instance
  • 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

    and by running:


    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

    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:

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