docker / for-win

Bug reports for Docker Desktop for Windows
https://www.docker.com/products/docker#/windows
1.87k stars 288 forks source link

Run JAR in windows native docker engine #1479

Closed sharathj007 closed 6 years ago

sharathj007 commented 6 years ago

Expected behavior

I have below docker file which has the TestJar.jar file which prints the hello world, when i am adding this into the dockerfile as below and creating an image by giving the below command as "docker build -t sample:jar ." Image is getting created successfully, but when try to run the image instead of showing hello world, which is throwing an error as below:

PS C:\Docker\DockerImageCreation\da-baseImage> docker run 023f0ffd426c
C:\Program Files\docker\docker.exe: Error response from daemon: container 6e0c71bef945a630c98dc4175526fb29b333ee053654c43ef278c3968b522816 encountered an error during CreateProcess: failure in a Windows system call: The system cannot find the file specified. (0x2) extra
info: {"ApplicationName":"","CommandLine":"c:\\Java\\jre1.8.0_91\\bin\\java.exe -version","User":"","WorkingDirectory":"C:\\","Environment":{"JAVA_HOME":"C:\\ojdkbuild","JAVA_OJDKBUILD_SHA256":"1905ea74b79d6d1d2ea2b2b6887c14770f090fbb8b46e7e1bfb56e92845e9cf2","JAVA_OJDKB
UILD_VERSION":"1.8.0.151-1","JAVA_OJDKBUILD_ZIP":"java-1.8.0-openjdk-1.8.0.151-1.b12.ojdkbuild.windows.x86_64.zip","JAVA_VERSION":"8u151"},"EmulateConsole":false,"CreateStdInPipe":true,"CreateStdOutPipe":true,"CreateStdErrPipe":true,"ConsoleSize":[0,0]}.

Actual behavior

When i run the image it should show a message "hello world", which is not happening.

Information

FROM openjdk:nanoserver
ADD /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 setx /M JRE_HOME C:\jre-8u91-windows-x64\jre
ADD /*.jar /
EXPOSE 8080
CMD java - jar TestJar.jar

CMD [ "c:\\Java\\jre1.8.0_91\\bin\\java.exe", "-version"]

PLEASE let me know how to run a sample .jar file in windows docker container.

thaJeztah commented 6 years ago

does it work if you change

ADD /*.jar /

to

COPY /*.jar /

The ADD command extracts local archives, which means it may extract the .jar

thaJeztah commented 6 years ago

Also note that your Dockerfile contains two CMD; the second will overwrite he first one

sharathj007 commented 6 years ago

Thanks for your suggestion, but i feel like the JRE path is not getting set properly to run the .jar file

thaJeztah commented 6 years ago

Does it work if you set it through ENV?

ENV JRE_HOME=C:\jre-8u91-windows-x64\jre

(perhaps the back-slashes need escaping, depending on what escape-character is set in the parent image)

sharathj007 commented 6 years ago

Thank you, how can i include JRE_HOME to PATH environment variable

sharathj007 commented 6 years ago

"RUN powershell start-process -filepath C:\jre-8u91-windows-x64.exe " will just start the process but JRE is not getting installed in the container. Due to this i am unable to run the .jar file in the container. Please provide a command to add in the dockerfile to install the JRE from the jre-8u91-windows-x64.exe inside container will be very much helpful.

thaJeztah commented 6 years ago

But why are you installing JRE again? Isn't it already present in the openjdk:nanoserver image? Here's, for example the example voting app; https://github.com/dockersamples/example-voting-app/blob/fe98cde7f47babebaa502412234ee5a009f4b543/worker/Dockerfile.j

(note that image is using an outdated version of openjdk, but the concept should be the same)

sharathj007 commented 6 years ago

Yeah sir, openjdk:nanoserver has the JRE within. But I am using microsoft/nanoserver as the base image and trying to install the JRE their. The above mentioned "RUN powershell start-process -filepath C:\jre-8u91-windows-x64.exe " wont install the in the container, it will just run and exit.

thaJeztah commented 6 years ago

Here's the Dockerfilie of the official openjdk:nanoserver image; https://github.com/docker-library/openjdk/blob/873fb56728befef8ecaf8436c3a27fd239cba301/8-jdk/windows/nanoserver-sac2016/Dockerfile, which may provide some hints how to install

sharathj007 commented 6 years ago

Thanks for your inputs, I am able to install the JDK in windowsservercore also successfully and able to run my sample .jar file their. Please let me know the installation commands for VC_redist.x64.exe, visual studio redistributable package through the docker file. Which is very much required to run my real time application as a docker image.

thaJeztah commented 6 years ago

Thanks for your inputs, I am able to install the JDK in windowsservercore also successfully and able to run my sample .jar file their.

Great!

Please let me know the installation commands for VC_redist.x64.exe, visual studio redistributable package through the docker file. Which is very much required to run my real time application as a docker image.

Looks like the first result searching on Google shows this; https://github.com/Microsoft/dotnet-framework-docker/issues/15

Please keep in mind that the GitHub issue tracker is not intended as a general support forum, but for reporting bugs and feature requests. For other type of questions, consider using one of;

I'm closing this issue because this is not a bug, but feel free to continue the conversation 👍

docker-robott commented 4 years ago

Closed issues are locked after 30 days of inactivity. This helps our team focus on active issues.

If you have found a problem that seems similar to this, please open a new issue.

Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows. /lifecycle locked