Park source container on duplicate so host ports can be reused
Release rolling / release (push) Has been cancelled
Release rolling / release (push) Has been cancelled
When duplicating with the same host ports, stop+rename the origin, deploy and verify the new container, then remove the parked source. Client precheck ignores ports owned only by the origin to avoid false blocks.
This commit is contained in:
@@ -108,19 +108,36 @@ export async function suggestNetworkIPAM(opts = {}) {
|
||||
|
||||
/**
|
||||
* Host ports published by containers.
|
||||
* Includes per-port owners so clients can ignore the source container when
|
||||
* duplicating (swap) without false host-port conflicts.
|
||||
*/
|
||||
export async function listUsedHostPorts() {
|
||||
const containers = await docker.listContainers({ all: true })
|
||||
/** @type {Set<number>} */
|
||||
const ports = new Set()
|
||||
/** @type {{ port: number, protocol: string, id: string, name: string }[]} */
|
||||
const owners = []
|
||||
for (const c of containers) {
|
||||
const id = String(c.Id || '')
|
||||
const name = String(c.Names?.[0] || '')
|
||||
.replace(/^\//, '') || id.slice(0, 12)
|
||||
for (const p of c.Ports || []) {
|
||||
if (p.PublicPort) ports.add(Number(p.PublicPort))
|
||||
if (!p?.PublicPort) continue
|
||||
const port = Number(p.PublicPort)
|
||||
if (!Number.isFinite(port)) continue
|
||||
ports.add(port)
|
||||
owners.push({
|
||||
port,
|
||||
protocol: String(p.Type || 'tcp').toLowerCase() === 'udp' ? 'udp' : 'tcp',
|
||||
id,
|
||||
name,
|
||||
})
|
||||
}
|
||||
}
|
||||
return {
|
||||
success: true,
|
||||
ports: [...ports].sort((a, b) => a - b),
|
||||
owners,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user