Search code examples
spring-bootdockervolumebuildpackpaketo

Dockerfile "VOLUME" equivalent when using Spring Boot Paketo Buildpack


I'm currently working on migrating the containerization of Spring Boot App from Dockerfile file to the Spring Boot Maven Plugin build-image.

Now I am wondering how to configure a volume in this scenario. The equivalent to having a VOLUME ["/var/store"] declartion in the Dockerfile. I already Googled for a while, help appreciated. THX!


Solution

  • It depends on the purpose.

    1. If you want to add a volume mount when the buildpacks are running, then you would add a <binding> to your pom.xml.

      https://docs.spring.io/spring-boot/docs/2.5.2/maven-plugin/reference/htmlsingle/#build-image.customization

      Volume bind mounts that should be mounted to the builder container when building the image. The bindings will be passed unparsed and unvalidated to Docker when creating the builder container.

      Bindings must be in one of the following forms:

      • <host source path>:<container destination path>[:<options>]

      • <host volume name>:<container destination path>[:<options>]

      Ex: results in /host/workspace being mounted into /workspace when the buildpacks execute

      <project>
          <build>
              <plugins>
                  <plugin>
                      <groupId>org.springframework.boot</groupId>
                      <artifactId>spring-boot-maven-plugin</artifactId>
                      <configuration>
                          <image>
                              <bindings>
                                 <binding>/host/workspace:/workspace</binding>
                              </bindings>
                          </image>
                      </configuration>
                  </plugin>
              </plugins>
          </build>
      </project>
      

      This would be the same as using the pack build --volume flag, if one is using the pack cli instead of Spring Boot's Maven plugin.

    2. You can bind volumes when you run your application. That simply uses the standard tools and arguments for your container runtime. For example, you can docker run -v and map in a volume.

    3. If you want the specific behavior of the VOLUME entry in a Dockerfile (which doesn't actually do 1 or 2 above), that's not exposed for images created using Buildpacks, which is what Spring Boot is using. If this is what you want, I would encourage you to read this SO post on volumes and reconsider if you really need it at all.