Reputation: 13
I want to serve my spring boot application via docker container, while setting up, it requires maven plugin(fabric8) to build a docker image for container, i don’t understand,
Upvotes: 1
Views: 2001
Reputation: 1982
Docker image is something that Spring Boot can't provide, because Spring Boot itself is a runtime framework, it tells to JVM how to run your code. Instead, Docker is about how to ship and run JVM itself. So, Spring Boot is a run-time framework, and Docker image is not something that you do at run-time. You can build Docker image only at build time, when your artifact (and Spring Boot) is not running yet.
Maven is a build tool, so when Maven performs a build, it can include building Docker image in whole build process. This can be done not only with Maven, but with any build tool that has Docker plugin. Maven is just a popular build tool, so it is often used in other framework manuals, but actually there is no dependency between Maven, Spring Boot and Docker. Maven just has all the tools to build Spring boot applications and also build Docker images.
To dockerize your app, you don't need Maven, but you need to somehow include building Docker image to build script for your application.
Upvotes: 1
Reputation: 5283
There are two ways of building docker image
1. Build a Docker Image with Maven
Add dockerfile maven plugin
<plugins>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.3.6</version>
<configuration>
<repository>${docker.image.prefix}/${project.artifactId}</repository>
<buildArgs>
<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
</plugins>
build the docker image using command line
./mvnw install dockerfile:build
2. Build a Docker image using Docker command
Run maven command
./mvnw clean install
Run the docker build command
docker build .
docker build -f /path/to/Dockerfile
Upvotes: 5