Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot & Docker using VOLUME /tmp

Is anyone able to explain why the Spring Boot Docker Guide recommends adding the /tmp volume as follows:

VOLUME /tmp

It explains:

We added a VOLUME pointing to "/tmp" because that is where a Spring Boot application creates working directories for Tomcat by default. The effect is to create a temporary file on your host under "/var/lib/docker" and link it to the container under "/tmp".

however, I'm not really clear why you'd want/need to do this.

If the java application creates any files in the /tmp directory of the container I don't see what the need is to configure this as a volume since, as far as I understand, it would result in files bypassing the union filesystem and being written persistently in the Docker host to /var/lib/docker. Could this also result in the "temporary" files created in the container not being automatically deleted when the container is stopped?

My spring boot app (which does create temporary files) seems to run ok without this VOLUME, but I wonder if there are any negative consequences to not following this advice.

Thanks.

like image 809
David Avatar asked May 26 '15 16:05

David


People also ask

What is an spring boot?

Spring Boot is an open source Java-based framework used to create a micro Service. It is developed by Pivotal Team and is used to build stand-alone and production ready spring applications.

Is spring boot and Java same?

Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications. It's a Java-based framework used to create a microservice ( microservice is defined as the small services that work together.

What is spring boot and MVC?

Spring Boot is considered a module of the Spring framework for packaging the Spring-based application with sensible defaults. Spring MVC is considered to be the model view controller-based web framework under the Spring framework. Use. For building a Spring-powered framework, default configurations are provided by it.

What is spring boot best for?

Spring Boot is the most popular framework for building microservice applications with Java. It speeds up the development and deployment processes by offering intuitive default settings for unit and integration tests, web applications, and more.


1 Answers

As said in the comments, because of the union file system, writing in the container is probably slower than writing in a volume.

Also, if you want to be able to reuse temporary files between container restart, using a volume is necessary but if this is not the case it would be probably better to use a tmpfs mount as described in the Docker documentation.

like image 150
Ortomala Lokni Avatar answered Oct 11 '22 10:10

Ortomala Lokni