Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it a good practice to put a war file image into docker containers?

I am new to docker. I have a Spring-boot application which I want to deploy and run using docker. Is it a good practice to put war file images in the container or it is better to put jar ones? why?

P.S. Once I read that it is better to "make jars , not wars" :-) but do not know the reason behind it.

like image 445
Lina Avatar asked Jul 29 '16 09:07

Lina


Video Answer


2 Answers

Matt's answer is correct, but you have to consider some further points.

  • Updates to the applicationserver: docker images of tomcat or glassfish are maintained by the responsible companies. If they find a nasty (security) bug they fix it and push a new version of that image to docker hub. To update your container to that secure version all you have to do is to rebuild your image and run a new version. If you bundle the applicationserver inside a jar you have to recompile your whole project to use that updated version. BTW most applicationservers have a autodeploy mechanism to deploy war's easily.
  • Dockers cache: if you build an image from a java base image and simply copy your fat jar on it, your whole image consists of one big layer. If you build another version of your app the big jar file changes causing docker to create another big layer. These two big layers both need space on your disc. On the other hand if you deploy a "small" war file to an applicationserver the two images share all layers until the layer with the war file. With these mechanism does docker improve your disc usage and speed up build times.
like image 110
Ohmen Avatar answered Oct 16 '22 22:10

Ohmen


One of the main reasons for building a docker image for your application is to provide an artefact that people can run without installing and managing external software dependencies (like an app server to run a war file).

From a container user perspective, it makes no difference whether you package your code in a jar or a war file or as a fortran binary. All they do is run a container image.

From your side, doing the Docker build and config management, packaging a jar file and copying will be a more simple solution than trying to setup and configure an app server to package then deploying each release into the app server. See Ohmens answer for some more technical components of the java build.

like image 29
Matt Avatar answered Oct 17 '22 00:10

Matt