MCPcopy Create free account
hub / github.com/vercel/vercel / readMappedHostPort

Function readMappedHostPort

packages/container/src/dev.ts:308–328  ·  view source on GitHub ↗

Read the host port Docker mapped for `containerPort` on a running container.

(
  containerName: string,
  containerPort: number,
  out: DevOutput
)

Source from the content-addressed store, hash-verified

306
307/** Read the host port Docker mapped for `containerPort` on a running container. */
308async function readMappedHostPort(
309 containerName: string,
310 containerPort: number,
311 out: DevOutput
312): Promise<number> {
313 const { stdout } = await runForwarded(
314 'docker',
315 ['port', containerName, `${containerPort}/tcp`],
316 out,
317 { quiet: true }
318 );
319 // Output like "0.0.0.0:54321" (possibly multiple lines for ipv4/ipv6).
320 const match = stdout.match(/:(\d+)\s*$/m);
321 if (!match) {
322 throw new Error(
323 `Could not determine mapped host port for ${containerName} ` +
324 `(${containerPort}/tcp). Got: ${stdout.trim()}`
325 );
326 }
327 return Number(match[1]);
328}
329
330function uniqueContainerName(serviceName: string): string {
331 const safe = serviceName.toLowerCase().replace(/[^a-z0-9-_.]/g, '-');

Callers 1

startContainerFunction · 0.85

Calls 2

runForwardedFunction · 0.85
matchMethod · 0.45

Tested by

no test coverage detected