Hey… 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 Dockerfilein 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 java-windows-docker
COPY c:\\testing
WORKDIR C:\\testing
RUN javac Hello.java
ENTRYPOINT ["java"]
CMD ["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. Even after installing java inside docker also i’m unable to run simple java program