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: 25th Jan, 2025 Have you ever wondered how to seamlessly integrate the vast…
Hey there! As I venture into building agentic MEAN apps with LangChain.js, I wanted to…
Software-as-a-Service (SaaS) providers have long relied on traditional chatbot solutions like AWS Lex and Google…
Retrieval-Augmented Generation (RAG) is an innovative generative AI method that combines retrieval-based search with large…
The combination of Retrieval-Augmented Generation (RAG) and powerful language models enables the development of sophisticated…
Have you ever wondered how to use OpenAI APIs to create custom chatbots? With advancements…