Following are the key points described later in this article:
Following is dockerfile to build Java 7 image. Save the file as java7.df for the code example (shell script startJava.sh) to work.
FROM centos:centos6 RUN mkdir /opt/jdk RUN cd /opt RUN yum -y install wget tar RUN wget --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x64.tar.gz RUN tar -zxf jdk-7u79-linux-x64.tar.gz -C /opt/jdk RUN update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.7.0_79/bin/java 100 RUN update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk1.7.0_79/bin/javac 100
Following is dockerfile to build Java8 image. Save the file as java8.df for the code example (shell script startJava.sh) to work.
FROM centos:centos6 RUN mkdir /opt/jdk RUN cd /opt RUN yum -y install wget tar RUN wget --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u5-b13/jdk-8u5-linux-x64.tar.gz RUN tar -zxf jdk-8u5-linux-x64.tar.gz -C /opt/jdk RUN update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.8.0_05/bin/java 100 RUN update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk1.8.0_05/bin/javac 100
Save the following script as startJava.sh. Save the above two dockerfiles as java7.df and java8.df in the same folder as the script below. Execute the command such as “./startJava.sh -v 7 java7” to start a Java 7 container with name as “java7” and, “./startJava.sh -v 8 java8” to start the Java 8 Container with name as “java8”. You could then access your source code on your m/c as the volume is mounted appropriately in the script below (/c/Users:/mnt/Users).
#!/bin/sh if [ $# == 0 ]; then echo "This script expecs version and container name as argument. Example: ./startJava.sh -v 7 java" exit 100 fi if [ $1 == '-v' ]; then expr $2 + 1 2> /dev/null if [ $? = 0 ]; then echo "Version: $2" else echo "Version can only be numeric. Value supported are 7, 8" exit 100 fi else echo "This script expecs version and container name as argument. Example: ./startJava.sh -v 7 java" exit 100 fi docker stop $3;docker rm $3 java_image="" java_df="" if [ $2 == 8 ]; then java_image="java8_base"#!/bin/sh if [ $# == 0 ]; then echo "This script expecs version and container name as argument. Example: ./startJava.sh -v 7 java" exit 100 fi if [ $1 == '-v' ]; then expr $2 + 1 2> /dev/null if [ $? = 0 ]; then echo "Version: $2" else echo "Version can only be numeric. Value supported are 7, 8" exit 100 fi else echo "This script expecs version and container name as argument. Example: ./startJava.sh -v 7 java" exit 100 fi docker stop $3;docker rm $3 java_image="" java_df="" if [ $2 == 8 ]; then java_image="java8_base" java_df="java8.df" else if [ $2 == 7 ]; then java_image="java7_base" java_df="java7.df" else echo "This script only supports Java containers for version 7 or 8. Please try again!" exit 100 fi fi # Build Java image if it does not exists # if [ `docker images $java_image | wc -l` -lt 2 ]; then echo "Docker Image $java_image do not exist..." echo "Builing docker image $java_image" if [ -f $java_df ]; then docker build -t $java_image -f $java_df . else echo "Can't find Dockerfile $java_df in the current location" exit 200 fi fi docker run --privileged=true -ti -dP --name $3 -v /c/Users:/mnt/Users $java_image /bin/bash docker exec -ti $3 /bin/bash java_df="java8.df" else if [ $2 == 7 ]; then java_image="java7_base" java_df="java7.df" else echo "This script only supports Java containers for version 7 or 8. Please try again!" exit 100 fi fi # Build Java image if it does not exists # if [ `docker images $java_image | wc -l` -lt 2 ]; then echo "Docker Image $java_image do not exist..." echo "Builing docker image $java_image" if [ -f $java_df ]; then docker build -t $java_image -f $java_df . else echo "Can't find Dockerfile $java_df in the current location" exit 200 fi fi docker run --privileged=true -ti -dP --name $3 -v /c/Users:/mnt/Users $java_image /bin/bash docker exec -ti $3 /bin/bash
Last updated: 3rd May, 2024 Have you ever wondered why some machine learning models perform…
Last updated: 2nd May, 2024 The success of machine learning models often depends on the…
When working on a machine learning project, one of the key challenges faced by data…
Last updated: 1st May, 2024 The bias-variance trade-off is a fundamental concept in machine learning…
Last updated: 1st May, 2024 As a data scientist, understanding the nuances of various cost…
Last updated: 1st May, 2024 In this post, you will learn the concepts related to…