Skip to content

Commit 8bd4f40

Browse files
authored
Merge pull request #3175 from Dokploy/3125-bug-additional-port-mapping---ui-glitch-crash-on-used-port-release-notes-warning
fix(settings): prevent duplicate port entries by only adding the firs…
2 parents 4873baa + 7ea7ee7 commit 8bd4f40

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

packages/server/src/services/settings.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -372,19 +372,27 @@ export const readPorts = async (
372372
publishedPort: number;
373373
protocol?: string;
374374
}[] = [];
375+
const seenPorts = new Set<string>();
375376
for (const key in parsedResult) {
376377
if (Object.hasOwn(parsedResult, key)) {
377378
const containerPortMapppings = parsedResult[key];
378379
const protocol = key.split("/")[1];
379380
const targetPort = Number.parseInt(key.split("/")[0] ?? "0", 10);
380381

381-
containerPortMapppings.forEach((mapping: any) => {
382-
ports.push({
383-
targetPort: targetPort,
384-
publishedPort: Number.parseInt(mapping.HostPort, 10),
385-
protocol: protocol,
386-
});
387-
});
382+
// Take only the first mapping to avoid duplicates (IPv4 and IPv6)
383+
const firstMapping = containerPortMapppings[0];
384+
if (firstMapping) {
385+
const publishedPort = Number.parseInt(firstMapping.HostPort, 10);
386+
const portKey = `${targetPort}-${publishedPort}-${protocol}`;
387+
if (!seenPorts.has(portKey)) {
388+
seenPorts.add(portKey);
389+
ports.push({
390+
targetPort: targetPort,
391+
publishedPort: publishedPort,
392+
protocol: protocol,
393+
});
394+
}
395+
}
388396
}
389397
}
390398
return ports.filter(

0 commit comments

Comments
 (0)