Two simple questions:
- Why is a Spring Boot application executed while creating a Docker image with the
mvnw spring-boot:build-image
command? - Is there a command line option to prevent this from happening?
I am building a Docker image for a Spring Boot application. The application depends on other, third party services which are not necessarily (and also shouldn’t be) available during the image build process. Hence, the image build fails, since the Spring Boot application checks those third party dependencies on start-up and tries to reconnect until they become available. Side remark: the latter cannot be changed since this is built-in in the framework for the third party service being used.
I also don’t understand why the application should actually be started to build a Docker image.
Thank you for responding and possibly the additional background information.
2
Answers
I found out an alternative approach might be to add an application.properties file in the src/test/resources folder in which you add
axon.axonserver.enabled=false
Doing so allows you to run tests without having a running Axon Server instance available.
This is probably not the best possible solution, but for now, it does the trick ;-)
I suspect that it’s not the application itself that’s being started, but its tests.
The
build-image
goal is bound to thepackage
phase of Maven’s lifecycle. To execute a goal in a particular phase, Maven has to execute every goal in each preceding phase first. The default lifecycle consists of the following phases:validate
– validate the project is correct and all necessary information is availablecompile
– compile the source code of the projecttest
– test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployedpackage
– take the compiled code and package it in its distributable format, such as a JAR.verify
– run any checks on results of integration tests to ensure quality criteria are metinstall
– install the package into the local repository, for use as a dependency in other projects locallydeploy
– done in the build environment, copies the final package to the remote repository for sharing with other developers and projects.As you can see,
validate
,compile
, andtest
all come beforepackage
.You can skip the tests – at the risk of building an image that doesn’t work – by invoking Maven with
-DskipTests
.