Should each docker image contain a jdk?

  • A+
Category:Languages

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 this service 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 200MB max. That means each docker image is, say 350MB at max. On the other hand, on my local PC I have only 1 JRE of 200MB and each application takes only a few MB of space.

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

Is this approach correct? Should "OpenJDK" from DockerHub be added to each image? Why is the size of image large even if the target PC may already have JDK?

 


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 it's checksum is 91e54dfb1179 in next picture, it will occupy your disk really.

But, if all your container then base all 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.

What you need to pay attention is to use the same base image for all java application as most as possible, and add different things to the Thin R/W layer.

Should each docker image contain a jdk?

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: