How to install multiple openjdk versions on alpine-based docker container












1















I wish to install jdk7 and jdk8 on an alpine container side by side. I would like to pick jdk7 only if an env variable is set.



I've chained FROM openjdk:7-alpine and FROM openjdk:8-alpine, but regardless of their relative order, the latter one overwrites the former. So, I am left with only 1 installation as seen in '/usr/lib/jvm'.



Why I need this:



I need this setup for a slave container for Jenkins. Now, jenkins remoting jar runs ONLY on jdk8 now. So, I need it. Plus, since I am spawning this container for a project which needs jdk7 as default jdk, I need that too.



My Dockerfile: https://github.com/ankurshashcode/docker-slave/blob/alpine/Dockerfile










share|improve this question





























    1















    I wish to install jdk7 and jdk8 on an alpine container side by side. I would like to pick jdk7 only if an env variable is set.



    I've chained FROM openjdk:7-alpine and FROM openjdk:8-alpine, but regardless of their relative order, the latter one overwrites the former. So, I am left with only 1 installation as seen in '/usr/lib/jvm'.



    Why I need this:



    I need this setup for a slave container for Jenkins. Now, jenkins remoting jar runs ONLY on jdk8 now. So, I need it. Plus, since I am spawning this container for a project which needs jdk7 as default jdk, I need that too.



    My Dockerfile: https://github.com/ankurshashcode/docker-slave/blob/alpine/Dockerfile










    share|improve this question



























      1












      1








      1








      I wish to install jdk7 and jdk8 on an alpine container side by side. I would like to pick jdk7 only if an env variable is set.



      I've chained FROM openjdk:7-alpine and FROM openjdk:8-alpine, but regardless of their relative order, the latter one overwrites the former. So, I am left with only 1 installation as seen in '/usr/lib/jvm'.



      Why I need this:



      I need this setup for a slave container for Jenkins. Now, jenkins remoting jar runs ONLY on jdk8 now. So, I need it. Plus, since I am spawning this container for a project which needs jdk7 as default jdk, I need that too.



      My Dockerfile: https://github.com/ankurshashcode/docker-slave/blob/alpine/Dockerfile










      share|improve this question
















      I wish to install jdk7 and jdk8 on an alpine container side by side. I would like to pick jdk7 only if an env variable is set.



      I've chained FROM openjdk:7-alpine and FROM openjdk:8-alpine, but regardless of their relative order, the latter one overwrites the former. So, I am left with only 1 installation as seen in '/usr/lib/jvm'.



      Why I need this:



      I need this setup for a slave container for Jenkins. Now, jenkins remoting jar runs ONLY on jdk8 now. So, I need it. Plus, since I am spawning this container for a project which needs jdk7 as default jdk, I need that too.



      My Dockerfile: https://github.com/ankurshashcode/docker-slave/blob/alpine/Dockerfile







      java docker jenkins slave






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 8:19









      piet.t

      10.1k73246




      10.1k73246










      asked Nov 15 '17 at 14:54









      Ankur SawhneyAnkur Sawhney

      1614




      1614
























          2 Answers
          2






          active

          oldest

          votes


















          6














          You should keep it simple and use one base image.

          Use openjdk7 as base image, install openjdk8 as a package.
          This will overwrite openjdk7 as the default JDK while leaving it in the image.



             # Example Dockerfile
          FROM openjdk:7-alpine
          RUN apk add --no-cache openjdk8

          # Other setup...


          Verify



          $> java -version
          openjdk version "1.8.0_131"
          OpenJDK Runtime Environment (IcedTea 3.4.0) (Alpine 8.131.11-r2)
          OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)

          $> ls /usr/lib/jvm/
          default-jvm java-1.7-openjdk java-1.8-openjdk





          share|improve this answer































            4














            You can use Docker multistage build to achieve that. You would basically copy the java installation from one image into another image. Here is what the dockerfile might look like:



            FROM openjdk:7-alpine as java7

            FROM openjdk:8-alpine
            COPY --from=java7 /usr/lib/jvm/java-1.7-openjdk /usr/lib/jvm/java-1.7-openjdk


            Now you will have both java installations with the jdk7 installation being under /usr/lib/jvm/java-1.7-openjdk






            share|improve this answer
























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47310526%2fhow-to-install-multiple-openjdk-versions-on-alpine-based-docker-container%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              6














              You should keep it simple and use one base image.

              Use openjdk7 as base image, install openjdk8 as a package.
              This will overwrite openjdk7 as the default JDK while leaving it in the image.



                 # Example Dockerfile
              FROM openjdk:7-alpine
              RUN apk add --no-cache openjdk8

              # Other setup...


              Verify



              $> java -version
              openjdk version "1.8.0_131"
              OpenJDK Runtime Environment (IcedTea 3.4.0) (Alpine 8.131.11-r2)
              OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)

              $> ls /usr/lib/jvm/
              default-jvm java-1.7-openjdk java-1.8-openjdk





              share|improve this answer




























                6














                You should keep it simple and use one base image.

                Use openjdk7 as base image, install openjdk8 as a package.
                This will overwrite openjdk7 as the default JDK while leaving it in the image.



                   # Example Dockerfile
                FROM openjdk:7-alpine
                RUN apk add --no-cache openjdk8

                # Other setup...


                Verify



                $> java -version
                openjdk version "1.8.0_131"
                OpenJDK Runtime Environment (IcedTea 3.4.0) (Alpine 8.131.11-r2)
                OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)

                $> ls /usr/lib/jvm/
                default-jvm java-1.7-openjdk java-1.8-openjdk





                share|improve this answer


























                  6












                  6








                  6







                  You should keep it simple and use one base image.

                  Use openjdk7 as base image, install openjdk8 as a package.
                  This will overwrite openjdk7 as the default JDK while leaving it in the image.



                     # Example Dockerfile
                  FROM openjdk:7-alpine
                  RUN apk add --no-cache openjdk8

                  # Other setup...


                  Verify



                  $> java -version
                  openjdk version "1.8.0_131"
                  OpenJDK Runtime Environment (IcedTea 3.4.0) (Alpine 8.131.11-r2)
                  OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)

                  $> ls /usr/lib/jvm/
                  default-jvm java-1.7-openjdk java-1.8-openjdk





                  share|improve this answer













                  You should keep it simple and use one base image.

                  Use openjdk7 as base image, install openjdk8 as a package.
                  This will overwrite openjdk7 as the default JDK while leaving it in the image.



                     # Example Dockerfile
                  FROM openjdk:7-alpine
                  RUN apk add --no-cache openjdk8

                  # Other setup...


                  Verify



                  $> java -version
                  openjdk version "1.8.0_131"
                  OpenJDK Runtime Environment (IcedTea 3.4.0) (Alpine 8.131.11-r2)
                  OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)

                  $> ls /usr/lib/jvm/
                  default-jvm java-1.7-openjdk java-1.8-openjdk






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 16 '17 at 3:09









                  stacksonstacksstacksonstacks

                  2,6321026




                  2,6321026

























                      4














                      You can use Docker multistage build to achieve that. You would basically copy the java installation from one image into another image. Here is what the dockerfile might look like:



                      FROM openjdk:7-alpine as java7

                      FROM openjdk:8-alpine
                      COPY --from=java7 /usr/lib/jvm/java-1.7-openjdk /usr/lib/jvm/java-1.7-openjdk


                      Now you will have both java installations with the jdk7 installation being under /usr/lib/jvm/java-1.7-openjdk






                      share|improve this answer




























                        4














                        You can use Docker multistage build to achieve that. You would basically copy the java installation from one image into another image. Here is what the dockerfile might look like:



                        FROM openjdk:7-alpine as java7

                        FROM openjdk:8-alpine
                        COPY --from=java7 /usr/lib/jvm/java-1.7-openjdk /usr/lib/jvm/java-1.7-openjdk


                        Now you will have both java installations with the jdk7 installation being under /usr/lib/jvm/java-1.7-openjdk






                        share|improve this answer


























                          4












                          4








                          4







                          You can use Docker multistage build to achieve that. You would basically copy the java installation from one image into another image. Here is what the dockerfile might look like:



                          FROM openjdk:7-alpine as java7

                          FROM openjdk:8-alpine
                          COPY --from=java7 /usr/lib/jvm/java-1.7-openjdk /usr/lib/jvm/java-1.7-openjdk


                          Now you will have both java installations with the jdk7 installation being under /usr/lib/jvm/java-1.7-openjdk






                          share|improve this answer













                          You can use Docker multistage build to achieve that. You would basically copy the java installation from one image into another image. Here is what the dockerfile might look like:



                          FROM openjdk:7-alpine as java7

                          FROM openjdk:8-alpine
                          COPY --from=java7 /usr/lib/jvm/java-1.7-openjdk /usr/lib/jvm/java-1.7-openjdk


                          Now you will have both java installations with the jdk7 installation being under /usr/lib/jvm/java-1.7-openjdk







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 15 '17 at 18:44









                          yamenkyamenk

                          14k31834




                          14k31834






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47310526%2fhow-to-install-multiple-openjdk-versions-on-alpine-based-docker-container%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              這個網誌中的熱門文章

                              Tangent Lines Diagram Along Smooth Curve

                              Yusuf al-Mu'taman ibn Hud

                              Zucchini