Skip to content

Commit e563ec5

Browse files
committed
Logs proper command when detecting rootless container runtime
e.g. Before: ``` WARN [io.qua.run.uti.ContainerRuntimeUtil] (main) Command "docker" exited with error code 1. Rootless container runtime detection might not be reliable. ``` after: ``` WARN [io.qua.run.uti.ContainerRuntimeUtil] (main) Command "docker info" exited with error code 1. Rootless container runtime detection might not be reliable or the container service is not running at all. ``` plus with `-Dquarkus.log.level=DEBUG` it logs: ``` DEBUG [io.qua.run.uti.ContainerRuntimeUtil] (main) Command "docker info" output: Client: Context: default Debug Mode: false Plugins: buildx: Docker Buildx (Docker Inc.) Version: v0.10.2 Path: /usr/libexec/docker/cli-plugins/docker-buildx compose: Docker Compose (Docker Inc.) Version: v2.16.0 Path: /usr/libexec/docker/cli-plugins/docker-compose scan: Docker Scan (Docker Inc.) Version: v0.23.0 Path: /usr/libexec/docker/cli-plugins/docker-scan Server: ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? ```
1 parent 34e9d5a commit e563ec5

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.io.InputStreamReader;
77
import java.nio.charset.StandardCharsets;
88
import java.util.function.Predicate;
9+
import java.util.stream.Collectors;
910

1011
import org.eclipse.microprofile.config.ConfigProvider;
1112
import org.jboss.logging.Logger;
@@ -80,31 +81,37 @@ private static String getVersionOutputFor(ContainerRuntime containerRuntime) {
8081

8182
private static boolean getRootlessStateFor(ContainerRuntime containerRuntime) {
8283
Process rootlessProcess = null;
84+
ProcessBuilder pb = null;
8385
try {
84-
ProcessBuilder pb = new ProcessBuilder(containerRuntime.getExecutableName(), "info")
85-
.redirectErrorStream(true);
86+
pb = new ProcessBuilder(containerRuntime.getExecutableName(), "info").redirectErrorStream(true);
8687
rootlessProcess = pb.start();
8788
int exitCode = rootlessProcess.waitFor();
8889
if (exitCode != 0) {
8990
log.warnf("Command \"%s\" exited with error code %d. " +
90-
"Rootless container runtime detection might not be reliable.",
91-
containerRuntime.getExecutableName(), exitCode);
91+
"Rootless container runtime detection might not be reliable or the container service is not running at all.",
92+
String.join(" ", pb.command()), exitCode);
9293
}
9394
try (InputStream inputStream = rootlessProcess.getInputStream();
9495
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
9596
BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
96-
Predicate<String> stringPredicate;
97-
// Docker includes just "rootless" under SecurityOptions, while podman includes "rootless: <boolean>"
98-
if (containerRuntime == ContainerRuntime.DOCKER) {
99-
stringPredicate = line -> line.trim().equals("rootless");
97+
if (exitCode != 0) {
98+
log.debugf("Command \"%s\" output: %s", String.join(" ", pb.command()),
99+
bufferedReader.lines().collect(Collectors.joining(System.lineSeparator())));
100+
return false;
100101
} else {
101-
stringPredicate = line -> line.trim().equals("rootless: true");
102+
Predicate<String> stringPredicate;
103+
// Docker includes just "rootless" under SecurityOptions, while podman includes "rootless: <boolean>"
104+
if (containerRuntime == ContainerRuntime.DOCKER) {
105+
stringPredicate = line -> line.trim().equals("rootless");
106+
} else {
107+
stringPredicate = line -> line.trim().equals("rootless: true");
108+
}
109+
return bufferedReader.lines().anyMatch(stringPredicate);
102110
}
103-
return bufferedReader.lines().anyMatch(stringPredicate);
104111
}
105112
} catch (IOException | InterruptedException e) {
106113
// If an exception is thrown in the process, assume we are not running rootless (default docker installation)
107-
log.debugf(e, "Failure to read info output from %s", containerRuntime.getExecutableName());
114+
log.debugf(e, "Failure to read info output from %s", String.join(" ", pb.command()));
108115
return false;
109116
} finally {
110117
if (rootlessProcess != null) {

0 commit comments

Comments
 (0)