Skip to content

Commit 3e9c6b4

Browse files
authored
Merge pull request #50771 from gsmet/improve-container-runtime-detection
Improve Docker and Podman CLI detection and error messages
2 parents 3144e47 + da38658 commit 3e9c6b4

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

core/deployment/src/main/java/io/quarkus/deployment/util/ContainerRuntimeUtil.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
package io.quarkus.deployment.util;
22

3+
import java.nio.file.Path;
34
import java.util.ArrayList;
45
import java.util.Arrays;
56
import java.util.List;
7+
import java.util.Optional;
68
import java.util.regex.Pattern;
79

810
import org.eclipse.microprofile.config.ConfigProvider;
911
import org.jboss.logging.Logger;
1012

1113
import io.smallrye.common.os.OS;
1214
import io.smallrye.common.process.ProcessBuilder;
15+
import io.smallrye.common.process.ProcessUtil;
1316
import io.smallrye.config.SmallRyeConfig;
1417

1518
public final class ContainerRuntimeUtil {
@@ -73,8 +76,8 @@ public static ContainerRuntime detectContainerRuntime(boolean required, boolean
7376
storeContainerRuntimeInSystemProperty(ContainerRuntime.UNAVAILABLE);
7477

7578
if (required) {
76-
throw new IllegalStateException("No container runtime was found. "
77-
+ "Make sure you have either Docker or Podman installed in your environment.");
79+
throw new IllegalStateException("No container CLI was found. "
80+
+ "Make sure you have either Docker or Podman CLI installed in your environment.");
7881
}
7982

8083
return ContainerRuntime.UNAVAILABLE;
@@ -147,7 +150,14 @@ private static ContainerRuntime fullyResolveContainerRuntime(ContainerRuntime co
147150
boolean silent) {
148151
String execName = containerRuntimeEnvironment.getExecutableName();
149152
try {
150-
return ProcessBuilder.newBuilder(execName)
153+
Optional<Path> execPath = ProcessUtil.pathOfCommand(Path.of(execName));
154+
if (execPath.isEmpty()) {
155+
// this should never happen as we have detected the presence of the Docker/Podman CLI before
156+
throw new IllegalStateException(
157+
String.format("Unable to find command: %s in $PATH: %s", execName, ProcessUtil.searchPath()));
158+
}
159+
160+
return ProcessBuilder.newBuilder(execPath.get())
151161
.arguments("info")
152162
.output().gatherOnFail(true).processWith(br -> {
153163
boolean rootless = false;
@@ -218,14 +228,20 @@ private static void storeContainerRuntimeInSystemProperty(ContainerRuntime conta
218228

219229
private static String getVersionOutputFor(ContainerRuntime containerRuntime) {
220230
String execName = containerRuntime.getExecutableName();
231+
Optional<Path> execPath = ProcessUtil.pathOfCommand(Path.of(execName));
232+
if (execPath.isEmpty()) {
233+
log.debugf("Unable to find command %s in $PATH: %s", execName, ProcessUtil.searchPath());
234+
return "";
235+
}
236+
221237
try {
222-
return ProcessBuilder.newBuilder(execName)
238+
return ProcessBuilder.newBuilder(execPath.get())
223239
.arguments("--version")
224240
.output().gatherOnFail(true).toSingleString(16384)
225241
.run();
226242
} catch (Throwable t) {
227243
// If an exception is thrown in the process, just return an empty String
228-
log.debugf(t, "Failure to read version output from %s", execName);
244+
log.debugf(t, "Failure to read version output from %s", execPath.get());
229245
return "";
230246
}
231247
}

docs/src/main/asciidoc/compose-dev-services.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ This integration provides a seamless development experience while giving you ful
3535
To use Compose Dev Services, you need:
3636

3737
1. A working *local* container environment: https://docs.docker.com/get-started/get-docker/[Docker] or https://podman.io/docs/installation[Podman]
38-
39-
2. Compose tooling such as `docker-compose` or `podman-compose`
40-
(Note that `docker compose` and `podman compose` commands internally call these binaries) :
38+
2. The `docker` or `podman` CLI present in the `$PATH`
39+
3. Compose tooling such as `docker-compose` or `podman-compose`
40+
(Note that `docker compose` and `podman compose` commands internally call these binaries):
4141

4242
* For Docker: https://docs.docker.com/compose/install/[Installing Docker Compose]
4343
* For Podman: https://podman-desktop.io/docs/compose/setting-up-compose[Setting up Compose]

0 commit comments

Comments
 (0)