Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should each Docker image contain a JDK?

Tags:

So, I'm very new to Docker. Let me explain the context to the question.

  1. I have 10 - 20 Spring Boot micro-service applications, each running on different ports on my local machine.

  2. But for migrating to Docker, based on my learning, each of the services must be in a different Docker container so as to quickly deploy or make copies.

  3. For each Docker container, we need to create a new Docker image.

  4. Each Docker image must contain a JRE for the Spring Boot application to run. It is around 200 MB maximum. That means each docker image is, say 350 MB at the maximum. On the other hand, on my local PC I have only one JRE of 200 MB and each application takes only a few MB of space.

  5. Based on this, I would need 600 MB on my local system, yet need 7 GB for all Docker images.

Is this approach correct? Should "OpenJDK" from DockerHub be added to each image?

Why is the size of the image large even if the target PC may already have the JDK?

like image 553
SamwellTarly Avatar asked Oct 17 '18 07:10

SamwellTarly


People also ask

Does Docker need JDK?

When creating a Docker image, we should only assign the necessary resources to function correctly. This means that we should start by using an appropriate Java Runtime Environment (JRE) for your production image and not the complete Java Development Kit (JDK).

Does Docker image contain Java?

In the Docker ecosystem, most Java images provide the JDK, so they are suitable to build and run Java code. We will also see some images with a :jre tag (or a tag containing jre somewhere). These are images containing only the JRE, without the full JDK.

Does each Docker container have its own JVM?

Yes, each container would run its own java process and thus its own JVM.

What Docker images contains?

A Docker image contains application code, libraries, tools, dependencies and other files needed to make an application run. When a user runs an image, it can become one or many instances of a container. Docker images have multiple layers, each one originates from the previous layer but is different from it.


1 Answers

Your understanding is not correct.

Docker images are formed with layers; see next diagram:

When you install a JRE in your image, let's suppose its checksum is 91e54dfb1179 in the next picture, it will occupy your disk really.

But, if all your containers are then all based on the same image, and add different things, says, your different microservice application to the thin R/W layer, all containers will share the 91e54dfb1179, so it will not be the n*m relationship.

You need to pay attention to using the same base image for all Java applications as much as possible, and add different things to the thin R/W layer.

Enter image description here

like image 200
atline Avatar answered Sep 17 '22 20:09

atline