Add fallback method for checking docker.

This commit is contained in:
Aria 2023-06-22 15:29:54 -07:00
parent d336e94546
commit eb5fc74e08

View file

@ -5,15 +5,14 @@ import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Stream;
public class EnvironmentUtils
{
public static boolean isRunningInsideDocker()
{
try{
Stream<String> str = Files.lines ( Paths.get ( "/proc/1/cgroup" ) );
return str.anyMatch ( ln->ln.contains ( "/docker" ) );
}catch( IOException e )
{
public class EnvironmentUtils {
public static boolean isRunningInsideDocker ( ) {
if ( Files.exists ( Paths.get ( "/.dockerenv" ) ) )
return true;
try {
Stream<String> str = Files.lines ( Paths.get ( "/proc/1/cgroup" ) );
return str.anyMatch ( ln -> ln.contains ( "/docker" ) );
} catch ( IOException e ) {
return false;
}
}