0

My question can be rephrased as: Pros and cons of docker or other container for Java application.

I found tons of information about Docker and VM, but I could not find an article about Java in Docker advantages.

A Java program is running as a JVM process, already a "so called" virtual machine. Why do many IT people want to run a Java program in docker?

There are tools to help manage docker containers: kubernetes, docker-compose, Docker Swarm, etc. It is easier to deploy the whole application (micro-services architecture, for example), with any custom config so easily: docker-compose up and docker-compose.yml defines the configuration. It is also easy to do orchestration and scaling with such tools.

Is it possible to manage JVM (Java Virtual Machines) in a similar way as we can manage containers? Is there such tool or technology out there? One hardcoded limited solution came to my mind is to make bash scripts to deploy all your application stack.

Before containers, we would run our applications in virtual machines in cloud. But a virtual machine is expensive (more resources are required to run your application, also there is a host OS, and VM OS). Docker technology allows to run your application process inside a container, using host OS ( assuming that container and host OS have the same kernel, for example both of them Linux based).

Another benefit of a container is ease for development. Instead of installing different dependencies for your application (databases, caches, application servers, proxy servers, etc), you can get images you need and run containers from them without installing these dependencies on your dev machine.

But again, why not run a JVM process on host machine for production? Example, we have five containers, and we know that they will be running a Java process there (it is important; otherwise it will make sense to use an individual container for each technology stack). So we can have one host machine with JRE installed, and we can run 5 JVM processes there without containers. Why not?

Yan Khonski
  • 12,225
  • 15
  • 76
  • 114

2 Answers2

1

As you are saying in the last bit of your question, a container is much cheaper than a VM, as it does not virtualise hardware and a OS as whole.

Also, when making a Docker image, it is made very easy to just grab a container and making it run instantly.

Ahmad
  • 11
  • 3
  • I agree, if I run a full VM with guest OS there. In my case, it is not a virtual machine with OS, but a Java Virtual Machine which is a process running on the host machine. – Yan Khonski Mar 20 '19 at 00:13
  • And I would like to learn from other people who are more experienced than me if they ever used a host machine to run JVM processes there for production without container technology (at this time, when container technology is heavily used)? And if they did not use containers, then why. – Yan Khonski Mar 20 '19 at 00:16
1

Let's imagine, you are running 5 JVM processes on your host.
How about if:
- You want to scale to other host if your application overloaded ( add more JVM process on other host by hand/script, config proxy, dns for new node). With docker orchestration tool, you can scale just by one click or deployment
- How about if process die, you need to write monitoring / cron script to make sure it alive and restart if it stopped. We can have self-healing with orchestration tool
And a lot of idea for orchestration tool :

Provisioning and deployment of containers
Redundancy and availability of containers
Scaling up or removing containers to spread application load evenly across host infrastructure
Movement of containers from one host to another if there is a shortage of resources in a host, or if a host dies
Allocation of resources between containers
External exposure of services running in a container with the outside world
Load balancing of service discovery between containers
Health monitoring of containers and hosts
Configuration of an application in relation to the containers running it

Though, Architecture of orchestration tool will be complex. We should decide base on purpose and current architecture

nct
  • 325
  • 3
  • 5
  • I agree with Orchestration, scaling and self-healing. What if someone creates an orchestration tool for JVM processes, a tool similar to containers tools. – Yan Khonski Mar 20 '19 at 09:28
  • Yes, it possible but why we need to make it while we have container for the same purpose. – nct Mar 20 '19 at 13:53