mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
feat: add utils to get docker host and check if running on WSL
This commit is contained in:
40
apps/dokploy/server/utils/docker.ts
Normal file
40
apps/dokploy/server/utils/docker.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { execAsync } from "@dokploy/server";
|
||||
|
||||
/** Returns if the current operating system is Windows Subsystem for Linux (WSL). */
|
||||
export const isWSL = async () => {
|
||||
try {
|
||||
const { stdout } = await execAsync("uname -r");
|
||||
const isWSL = stdout.includes("microsoft");
|
||||
return isWSL;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/** Returns the Docker host IP address. */
|
||||
export const getDockerHost = async (): Promise<string> => {
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
if (process.platform === "linux" && !isWSL()) {
|
||||
try {
|
||||
// Try to get the Docker bridge IP first
|
||||
const { stdout } = await execAsync(
|
||||
"ip route | awk '/default/ {print $3}'",
|
||||
);
|
||||
|
||||
const hostIp = stdout.trim();
|
||||
if (!hostIp) {
|
||||
throw new Error("Failed to get Docker host IP");
|
||||
}
|
||||
|
||||
return hostIp;
|
||||
} catch (error) {
|
||||
console.error("Failed to get Docker host IP:", error);
|
||||
return "172.17.0.1"; // Default Docker bridge network IP
|
||||
}
|
||||
}
|
||||
|
||||
return "host.docker.internal";
|
||||
}
|
||||
|
||||
return "localhost";
|
||||
};
|
||||
Reference in New Issue
Block a user