Files
dokploy/apps/dokploy/server/utils/docker.ts
T
Mauricio Siu 8ab6d6b282 chore: clean up unused variables and improve error handling across codebase
This commit focuses on removing unused variables, adding placeholder error handling, and generally tidying up various files across the Dokploy application. Changes include:

- Removing unused imports and variables
- Adding placeholder error handling in catch blocks
- Cleaning up commented-out code
- Removing deprecated utility files
- Improving type safety and code consistency
2025-02-22 20:35:21 -06:00

41 lines
1.0 KiB
TypeScript

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" && !(await 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";
};