How can I use java installed in container 1 to run a jar in container 2

I am having two docker containers. Lets call them container 1 and container 2.
I can install stuff in only one of those. I have to run a jar file in container 1 in which I am not permitted to install anything. As such I install java in container 2 and then use

docker run --volumes-from container2 <all files need to run java from container 2>:<path in container 1> and then run the jar in container 1. 

Can I Somehow do this ?

I am thinking of making a folder on container 2 and installing all java stuff in that particular folder and then mounting it all into container 1 and exporting JAVA_HOME but am not sure if that is possible.

TIA

Answer

There is a problem with the image1 design : it must have inside all the stuff to run the jar.

If you can’t modify the image1 Dockerfile, then build another image “image3” by yourself, starting from image1, and add all the stuff you need inside.

Attribution
Source : Link , Question Author : The_Lost_Avatar , Answer Author : Chaoxiang N

Leave a Comment