Search code examples
javaspringspring-bootdocker-compose

Spring Boot application fails to start with Unable to start docker process


I have a simple Spring Boot 3.2.3 application. After trying to integrate the Docker Compose support, the application is unable to start with a rather confusing message: Unable to start docker process. Is docker correctly installed? — similar to this issue.

I do have Docker installed — I use it extensively, so this cannot be the problem. The compose.yaml file (located in the project's root) is valid:

$ docker compose version 
Docker Compose version 2.26.1
$ docker compose config --quiet
$ docker compose up --detach --remove-orphans 
[+] Running 10/10
 ✔ database Pulled                                                                                                                                                                                             6.3s 
   ✔ 4abcf2066143 Pull complete                                                                                                                                                                                0.3s 
   ✔ 128d1b74d24d Pull complete                                                                                                                                                                                0.2s 
   ✔ 0a392327555d Pull complete                                                                                                                                                                                0.2s 
   ✔ 0e14a31643e8 Pull complete                                                                                                                                                                                2.4s 
   ✔ 904e95badb7d Pull complete                                                                                                                                                                                0.7s 
   ✔ 8f6103a2e811 Pull complete                                                                                                                                                                                0.8s 
   ✔ 02b106837f9f Pull complete                                                                                                                                                                                0.9s 
   ✔ d34b010d3edc Pull complete                                                                                                                                                                                1.0s 
   ✔ 696a345da38f Pull complete                                                                                                                                                                                1.2s 
[+] Running 3/3
 ✔ Network spring-boot-rest-sandbox  Created                                                                                                                                                                   0.0s 
 ✔ Volume "postgres-data-volume"     Created                                                                                                                                                                   0.0s 
 ✔ Container database                Started

$ uname -a 
Linux uplink 6.6.23-1-lts #1 SMP PREEMPT_DYNAMIC Wed, 27 Mar 2024 07:47:20 +0000 x86_64 GNU/Linux

Regardless, every time I run the application, it fails to start:

$ ./gradlew bootRun
> Task :generateEffectiveLombokConfig UP-TO-DATE
> Task :compileJava UP-TO-DATE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :resolveMainClassName UP-TO-DATE

2024-04-05 18:00:07,039 |- DEBUG in org.acme.Application:51 [main] - Running with Spring Boot v3.2.3, Spring v6.1.4
2024-04-05 18:00:07,040 |-  INFO in org.acme.Application:660 [main] - The following 1 profile is active: "dev"
2024-04-05 18:00:07,194 |- ERROR in o.s.boot.SpringApplication:851 [main] - Application run failed
org.springframework.boot.docker.compose.core.DockerProcessStartException: Unable to start docker process. Is docker correctly installed?
        at org.springframework.boot.docker.compose.core.DockerCli$DockerCommands.getDockerCommand(DockerCli.java:140)
        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:1228)
        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:185)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:178)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:156)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138)
        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:432)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:333)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1354)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343)
        at org.acme.Application.main(Application.java:23)
Caused by: org.springframework.boot.docker.compose.core.ProcessStartException: Unable to start command docker version --format {{.Client.Version}}
        at org.springframework.boot.docker.compose.core.ProcessRunner.startProcess(ProcessRunner.java:115)
        at org.springframework.boot.docker.compose.core.ProcessRunner.run(ProcessRunner.java:87)
        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)
        ... 25 common frames omitted
Caused by: java.io.IOException: Cannot run program "docker": error=2, No such file or directory
        at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1170)
        at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1089)
        at org.springframework.boot.docker.compose.core.ProcessRunner.startProcess(ProcessRunner.java:105)
        ... 28 common frames omitted
Caused by: java.io.IOException: error=2, No such file or directory
        at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
        at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:295)
        at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:225)
        at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1126)
        ... 30 common frames omitted

Any suggestions on how to move forward with this integration and achieve the desired behavior?


Solution

  • I've managed to resolve the problem, although the exact cause remains unclear to me. I didn't make any modifications, but the feature now works as expected.

    I did verify that /usr/bin was correctly added to PATH, yet initially encountered difficulties.

    $ ./gradlew bootRun 
    Configuration on demand is an incubating feature.
    > Task :generateEffectiveLombokConfig FROM-CACHE
    > Task :compileJava
    > Task :processResources UP-TO-DATE
    > Task :classes
    > Task :resolveMainClassName
    
    > Task :bootRun
    
    ...
    
    2024-04-10 17:08:38,836 |- DEBUG in org.acme.Application:51 [main] - Running with Spring Boot v3.2.4, Spring v6.1.5
    2024-04-10 17:08:38,836 |-  INFO in org.acme.Application:660 [main] - The following 1 profile is active: "dev"
    2024-04-10 17:08:41,667 |-  WARN in liquibase.lockservice:37 [main] - Failed to release change log lock
    All objects dropped from spring-boot@jdbc:postgresql://127.0.0.1:5432/spring-boot
    Running Changeset: database/migrations/changelog-1.sql::1::liquibase
    Liquibase: Update has been successful. Rows affected: 1
    2024-04-10 17:08:42,004 |-  INFO in o.s.b.w.e.netty.NettyWebServer:141 [main] - Netty started on port 8080
    2024-04-10 17:08:42,011 |-  INFO in org.acme.Application:56 [main] - Started Application in 3.451 seconds (process running for 3.655)
    

    I'll update the answer if I encounter any further issue(s) — and I'm able to pinpoint the cause.


    UPDATE I

    Somehow, I think the Gradle daemon is playing tricks here. I've managed to replicate this. Problem is that I'm using the Flatpak version of IntelliJ IDEA, so if I initially start the application from the IDE, it fails to start with the error that it can't find the docker / docker compose commands.

    It gets confusing because when I then go to the operating system's terminal, the PATH does have /usr/bin, but somehow the Gradle daemon may not have the correct settings (or something around those lines), and the application still fails to start.

    If I kill the Gradle daemon and start the application from the operating system's terminal, everything is fine — but in turn, I get a weird error then if I want to start it from the IDE:

    1:49:05 PM: Executing ':classes'...
    
    FAILURE: Build failed with an exception.
    
    * What went wrong:
    The specified initialization script '/tmp/ijMapper1.gradle' does not exist.
    
    * Try:
    > Run with --stacktrace option to get the stack trace.
    > Run with --info or --debug option to get more log output.
    > Run with --scan to get full insights.
    > Get more help at https://help.gradle.org.
    
    BUILD FAILED in 611ms