Skip to content

Spring Boot Docker Compose reports exit code 0 on application run failed #40079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bnhmn opened this issue Mar 22, 2024 · 2 comments
Closed

Spring Boot Docker Compose reports exit code 0 on application run failed #40079

bnhmn opened this issue Mar 22, 2024 · 2 comments

Comments

@bnhmn
Copy link

bnhmn commented Mar 22, 2024

I have a simple Spring Boot project and a docker-compose.yaml file, in which among other things a container for a Postgres database is configured. I use Spring Boot Docker Compose to automatically start the database when starting the application.
I noticed that if the Docker command returns an error and the application fails to start, no corresponding exit code (!= 0) is returned to the shell.

Spring Boot version: 3.1.9

Example 1

I start the application with mvn spring-boot:run.
The error message Application run failed ... Docker is not running appears.
However, Maven unexpectedly returns a BUILD SUCCESS with exit code 0.

Log output
   .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.1.9)

2024-03-22 12:41:15.352  INFO no-application-context 5120   --- [  restartedMain] a.b.c.d.e.f.g.sample.demo.Application    : Starting Application using Java 17.0.6 with PID 93713 (/path/to/my/application/target/classes started by user123 in /path/to/my/application)
2024-03-22 12:41:15.352 DEBUG no-application-context 5121   --- [  restartedMain] a.b.c.d.e.f.g.sample.demo.Application    : Running with Spring Boot v3.1.9, Spring v6.0.17
2024-03-22 12:41:15.353  INFO no-application-context 5122   --- [  restartedMain] a.b.c.d.e.f.g.sample.demo.Application    : The following 1 profile is active: "local"
2024-03-22 12:41:15.374  INFO no-application-context 5124   --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2024-03-22 12:41:15.374  INFO no-application-context 5125   --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2024-03-22 12:41:15.389  INFO no-application-context 5126   --- [  restartedMain] .s.b.d.c.l.DockerComposeLifecycleManager : Using Docker Compose file '/path/to/my/application/docker-compose.yaml'
2024-03-22 12:41:16.292 ERROR no-application-context 5127   --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed
org.springframework.boot.docker.compose.core.DockerNotRunningException: Docker is not running
        at org.springframework.boot.docker.compose.core.DockerCli$DockerCommands.getDockerCommand(DockerCli.java:146)
        at org.springframework.boot.docker.compose.core.DockerCli$DockerCommands.<init>(DockerCli.java:129)
        at org.springframework.boot.docker.compose.core.DockerCli.lambda$new$0(DockerCli.java:65)
        at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1220)
        at org.springframework.boot.docker.compose.core.DockerCli.<init>(DockerCli.java:64)
        at org.springframework.boot.docker.compose.core.DockerCompose.get(DockerCompose.java:92)
        at org.springframework.boot.docker.compose.lifecycle.DockerComposeLifecycleManager.getDockerCompose(DockerComposeLifecycleManager.java:154)
        at org.springframework.boot.docker.compose.lifecycle.DockerComposeLifecycleManager.start(DockerComposeLifecycleManager.java:110)
        at org.springframework.boot.docker.compose.lifecycle.DockerComposeListener.onApplicationEvent(DockerComposeListener.java:53)
        at org.springframework.boot.docker.compose.lifecycle.DockerComposeListener.onApplicationEvent(DockerComposeListener.java:35)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:174)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:145)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:133)
        at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136)
        at org.springframework.boot.context.event.EventPublishingRunListener.contextLoaded(EventPublishingRunListener.java:98)
        at org.springframework.boot.SpringApplicationRunListeners.lambda$contextLoaded$4(SpringApplicationRunListeners.java:72)
        at java.base/java.lang.Iterable.forEach(Iterable.java:75)
        at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118)
        at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112)
        at org.springframework.boot.SpringApplicationRunListeners.contextLoaded(SpringApplicationRunListeners.java:72)
        at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:420)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:323)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1317)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
        at com.audi.awsi.service.onepaymentprofile.Application.main(Application.java:14)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:50)
Caused by: org.springframework.boot.docker.compose.core.ProcessExitException: 'docker version --format {{.Client.Version}}' failed with exit code 1.

Stdout:
23.0.1


Stderr:
Cannot connect to the Docker daemon at unix:///Users/user123/.colima/default/docker.sock. Is the docker daemon running?

        at org.springframework.boot.docker.compose.core.ProcessRunner.run(ProcessRunner.java:96)
        at org.springframework.boot.docker.compose.core.ProcessRunner.run(ProcessRunner.java:74)
        at org.springframework.boot.docker.compose.core.DockerCli$DockerCommands.getDockerCommand(DockerCli.java:135)
        ... 30 common frames omitted
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.775 s
[INFO] Finished at: 2024-03-22T12:41:16+01:00
[INFO] ------------------------------------------------------------------------

Example 2

I test the application with mvn verify -Dspring.docker.compose.skip.intests.false.
The error message Application run failed ... Docker is not running appears several times.
However, Maven unexpectedly returns a BUILD SUCCESS with exit code 0 and Tests run: 0, Failures: 0, Errors: 0, Skipped: 0.

The CI/CD pipeline incorrectly reports that all tests have been successful.
However, my expectation is that an exit code != 0 is returned to the shell and the test error is correctly reported in CI/CD.

How to Reproduce

  1. Set up a Spring Boot project including Spring Boot Docker Compose
  2. Create a docker-compose.yaml file with a sample container
  3. Provoke a Docker error (e.g. shutdown docker daemon)
  4. Execute the command mvn spring-boot:run
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 22, 2024
@wilkinsona
Copy link
Member

You haven't mentioned it, by I can tell from the log output that, in example 1, you're using spring-boot-devtools. The problem that you're seeing is a duplicate of #28541.

I cannot reproduce the behavior you have described in example 2, either with or without spring-boot-devtools on the classpath. If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Mar 22, 2024
@bnhmn
Copy link
Author

bnhmn commented Mar 22, 2024

You haven't mentioned it, by I can tell from the log output that, in example 1, you're using spring-boot-devtools. The problem that you're seeing is a duplicate of #28541.

You're right. Removing spring-boot-devtools fixes issue in example 1.

Regarding example 2:
After lots of debugging it seems that it was not related to Spring but an issue with the Maven Surefire plugin version 3.0.0-M4.
I have upgraded to latest version 3.2.5 and now the Docker Compose error is correctly reflected in the exit code.

Issue is resolved.

@bnhmn bnhmn closed this as completed Mar 22, 2024
@scottfrederick scottfrederick closed this as not planned Won't fix, can't repro, duplicate, stale Mar 22, 2024
@scottfrederick scottfrederick removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged labels Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants