3

Lets consider a scenario. I have one server. I installed Java 8 on the host machine.I need to deployed 4 docker containers having java web Applications each.

My question is that can java installed on host server manage deployed Apps in docker containers or I have to install java 8 in each container. If I have to install java in each container then what is difference between VMs and Containers because we also install OS (Minimum) in each container.

Goforseeking
  • 385
  • 1
  • 3
  • 15
  • Yes, you need Java in each container. http://stackoverflow.com/questions/16047306/how-is-docker-different-from-a-normal-virtual-machine – gogasca May 12 '16 at 05:50
  • Well, you could mount a shared JVM installation host directory into each container. But that defeats the purpose of Docker. If you want to depend on the host having Java, you could probably just build jar/war files instead. Note that if all your images are based off a common image with the JDK installed already, at least they share disk space for that. – Thilo May 12 '16 at 05:56
  • Possible duplicate of [Reuse host binaries or share between containers in Docker](http://stackoverflow.com/questions/28252447/reuse-host-binaries-or-share-between-containers-in-docker) – Thilo May 12 '16 at 06:01

2 Answers2

0

It doesn't matter whether your host has Java or not.

You will need a Java docker image, just do a search on dockerhub for some. Then build your application off that image and spin the image up as containers.

https://hub.docker.com/

You mentioned web application, so you will have to make sure that the host port that you are mapping from the container is unique. E.g. I believe you can't have java container #1 to #4 mapping to the same host port 1234.

It will have to be something like Java web container #1's port 123 mapped to host 100, then container #2 port 123 mapped to host port 101.

Hope this helps.

Samuel Toh
  • 18,006
  • 3
  • 24
  • 39
0

Two Scenarios,

  1. You want to use OpenJDK:

    You can base all your containers off official Java images like below,

     FROM java:8
     ...
     ...
    
  2. You want to use Oracle Java:

    You create a Dockerfile

     FROM  centos:7
     RUN yum update -y && \
     yum install -y wget && \
     wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/7u80-b15/jdk-7u80-linux-x64.rpm" && \
     yum localinstall -y jdk-7u80-linux-x64.rpm && \
     rm -f jdk-7u80-linux-x64.rpm && \
     yum clean all
    
     ENV JAVA_HOME /usr/java/jdk1.7.0_80
     ENV PATH $JAVA_HOME:$PATH
    
     CMD ["/bin/bash"]
    

Then you build base java image

    docker build -t my-oracla-java:8 .

then base all your container images off your java images

FROM my-oracla-java:8
...
...
RAY
  • 2,201
  • 2
  • 19
  • 18
pinkal vansia
  • 10,240
  • 5
  • 49
  • 62