Greg
Greg

Reputation: 11512

Is there any way, from inside a Java program, to detect if its running in a Docker?

Title says it. I'm running a Java program, and from within the program I'd like to detect whether its running inside a Docker container or not.

Upvotes: 8

Views: 1201

Answers (1)

queeg
queeg

Reputation: 9384

According to https://stackoverflow.com/a/25518345/4222206

public boolean isDockerized() {
    File f = new File("/.dockerenv");
    return f.exists();
}

Upvotes: 4

Related Questions