psys automatically detects Docker containers and their published ports, providing visual indicators and container name labels in the network visualization.
psys uses the docker ps command to discover running containers:
Copy
Ask AI
function getDockerPortToContainer(): Map<number, string> { const byPort = new Map<number, string>(); try { const out = execSync("docker ps --format '{{.Ports}}\t{{.Names}}'", { encoding: "utf8", stdio: ["pipe", "pipe", "ignore"], }); for (const line of out.split("\n").filter(Boolean)) { const [ports, names] = line.split("\t"); if (!ports || !names) continue; for (const p of ports.split(", ")) { const match = p.match(/(?:[\d.]+:)?(\d+)->\d+/); const port = match ? parseInt(match[1], 10) : parseInt(p.split("/")[0], 10); if (port && !byPort.has(port)) byPort.set(port, names); } } } catch { // ignore - docker not available or not running } return byPort;}
If Docker is not installed or not running, psys gracefully continues without Docker integration.
Docker container names are used to improve icon detection:
Copy
Ask AI
function getProcessIconType( processName: string, containerName: string | undefined, port: number): string | undefined { const name = processName.toLowerCase(); const container = (containerName ?? "").toLowerCase(); // Process name detection if (name.includes("node") || name === "mainthread") return "node"; if (name.includes("redis")) return "redis"; // ... more process checks // Container name detection if (container.includes("redis")) return "redis"; if (container.includes("mongo")) return "mongo"; if (container.includes("postgres")) return "postgres"; if (container.includes("mysql")) return "mysql"; // Fall back to port-based detection return PORT_ICON_TYPE[port] ?? "generic";}
Name your Docker containers descriptively (e.g., my-redis, api-postgres) to enable automatic icon detection.
Docker container names are also used to label connection targets:
Copy
Ask AI
function getDockerPortLabels(): Map<string, string> { const labels = new Map<string, string>(); try { const out = execSync("docker ps --format '{{.Ports}}\t{{.Names}}\t{{.Image}}'", { encoding: "utf8", stdio: ["pipe", "pipe", "ignore"], }); for (const line of out.split("\n").filter(Boolean)) { const [ports, names] = line.split("\t"); if (!ports || !names) continue; const portMappings = ports.split(", "); for (const p of portMappings) { const match = p.match(/(?:[\d.]+:)?(\d+)->\d+/); const port = match ? match[1] : p.split("/")[0]; if (port) labels.set(`127.0.0.1:${port}`, names); labels.set(`0.0.0.0:${port}`, names); } } } catch { // docker not available or not running } return labels;}
This creates a mapping from address:port to container name, which is used when building connection labels:
Copy
Ask AI
let toLabel = dockerLabels.get(toKey) || knownPortLabel(toPort);