mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-06-16 04:35:24 +02:00
fix(settings): prevent duplicate port entries by only adding the first mapping for each target port
This commit is contained in:
@@ -372,19 +372,27 @@ export const readPorts = async (
|
||||
publishedPort: number;
|
||||
protocol?: string;
|
||||
}[] = [];
|
||||
const seenPorts = new Set<string>();
|
||||
for (const key in parsedResult) {
|
||||
if (Object.hasOwn(parsedResult, key)) {
|
||||
const containerPortMapppings = parsedResult[key];
|
||||
const protocol = key.split("/")[1];
|
||||
const targetPort = Number.parseInt(key.split("/")[0] ?? "0", 10);
|
||||
|
||||
containerPortMapppings.forEach((mapping: any) => {
|
||||
ports.push({
|
||||
targetPort: targetPort,
|
||||
publishedPort: Number.parseInt(mapping.HostPort, 10),
|
||||
protocol: protocol,
|
||||
});
|
||||
});
|
||||
// Take only the first mapping to avoid duplicates (IPv4 and IPv6)
|
||||
const firstMapping = containerPortMapppings[0];
|
||||
if (firstMapping) {
|
||||
const publishedPort = Number.parseInt(firstMapping.HostPort, 10);
|
||||
const portKey = `${targetPort}-${publishedPort}-${protocol}`;
|
||||
if (!seenPorts.has(portKey)) {
|
||||
seenPorts.add(portKey);
|
||||
ports.push({
|
||||
targetPort: targetPort,
|
||||
publishedPort: publishedPort,
|
||||
protocol: protocol,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ports.filter(
|
||||
|
||||
Reference in New Issue
Block a user