I am just a beginner to Docker and was exploring the various features. I have successfully installed java inside docker
**OS version**:Windows Server 2016
PS C:\testing> docker version
Client:
Version: 17.03.1-ee-3
API version: 1.27
Go version: go1.7.5
Git commit: 3fcee33
Built: Thu Mar 30 19:31:22 2017
OS/Arch: windows/amd64
Server:
Version: 17.03.1-ee-3
API version: 1.27 (minimum version 1.24)
Go version: go1.7.5
Git commit: 3fcee33
Built: Thu Mar 30 19:31:22 2017
OS/Arch: windows/amd64
Experimental: false
PS C:\testing>
Created a Dockerfile in the path C:\java-windows-docker\Dockerfile
, and put the following lines inside:
FROM windowsservercore
RUN powershell (new-object
System.Net.WebClient).Downloadfile('http://javadl.oracle.com/webapps/download/AutoDL?
BundleId=210185', 'C:\jre-8u91-windows-x64.exe')
RUN powershell start-process -filepath C:\jre-8u91-windows-x64.exe -passthru -wait -argumentlist"/s,INSTALLDIR=c:\Java\jre1.8.0_91,/L,install64.log"
RUN del C:\jre-8u91-windows-x64.exe
CMD [ "c:\\Java\\jre1.8.0_91\\bin\\java.exe", "-version"]
It downloads the Java 8 Update 91 Windows installer and silently installs it to c:\Java\jre1.8.0_91.
docker build -t java-windows-docker C:\java-windows-docker
And if we run it, after start, the container launches Java and prints out its version.
PS C:\Windows\system32> docker run java-windows-docker
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b15, mixed mode)
We have Java running. inside a Windows docker container which is hosted on a Windows server 2016
I want to run a simple java program. The code within java files are as below:
class Hello{
public static void main(String[] args){
System.out.println("This is java app \n by using Docker");
}
}
Then as the next step I built the image for the above program. Dockerfile
for building java program
FROM testing
WORKDIR C:\\testing
RUN javac Hello.java
CMD ["java","Hello"]
When I build the image, I get shown the below error:
PS C:\testing> docker build -t testing C:\testing Sending build context to Docker daemon 11.78 kB Step 1/5 : FROM java-windows-docker ---> 534f46817a18 Step 2/5 : WORKDIR C:\testing ---> fc954983c8b0 Removing intermediate container 5e30071d9159 Step 3/5 : RUN javac Hello.java ---> Running in c91c62ba707c javac' is not recognized as an internal or external command, operable program or batch file. The command 'cmd /S /C javac Hello.java' returned a non-zero code: 1
Any advise on this would be helpful. If possible Kindly help me with the sample Dockerfile to run this java program. I have been working on this for the past two days i can't get this to work. I'm wondering how to set the path inside the docker image and how this actually works.i have also tried to set the path
ENV JAVA_HOME C:\Java\jre1.8.0_91\bin;
RUN setx PATH %PATH%;%JAVA_HOME%\bin
RUN setx CLASSPATH %CLASSPATH%;C:\Java\jre1.8.0_91;C:\testing;.;
But it doesn't work. I dont know when to set this path while building the java image or running the java program. Kindly advise.Thanks in advance