Skip to content

Commit

Permalink
Catch possible exceptions
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <[email protected]>
  • Loading branch information
dbwiddis committed Jul 6, 2022
1 parent cb96c2f commit b29938f
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;

Expand Down Expand Up @@ -101,11 +102,16 @@ private static boolean isRunningInDocker() {
if (new File("/.dockerenv").exists()) {
return true;
}
// Backup 1: look for 'docker' in one of the paths in /proc/1/cgroup
if (Files.lines(Path.of("/proc/1/cgroup")).anyMatch(line -> line.contains("docker"))) {
return true;
try {
// Backup 1: look for 'docker' in one of the paths in /proc/1/cgroup
if (Files.lines(Path.of("/proc/1/cgroup")).anyMatch(line -> line.contains("docker"))) {
return true;
}
// Backup 2: look for 'docker' in overlay fs
return Files.lines(Path.of("/proc/1/mounts"))
.anyMatch(line -> line.startsWith("overlay") && line.contains("docker"));
} catch (InvalidPathException | IOException e) {
return false;
}
// Backup 2: look for 'docker' in overlay fs
return Files.lines(Path.of("/proc/1/mounts")).anyMatch(line -> line.startsWith("overlay") && line.contains("docker"));
}
}

0 comments on commit b29938f

Please sign in to comment.