MCPcopy
hub / github.com/dgraph-io/dgraph / publicPort

Function publicPort

dgraphtest/dgraph.go:393–424  ·  view source on GitHub ↗
(dcli *docker.Client, dc dnode, privatePort string)

Source from the content-addressed store, hash-verified

391}
392
393func publicPort(dcli *docker.Client, dc dnode, privatePort string) (string, error) {
394 // TODO(aman): we should cache the port information
395
396 if runtime.GOOS == "darwin" {
397 return getPortMappingsOnMac(dc.cid(), privatePort)
398 }
399
400 ctx, cancel := context.WithTimeout(context.Background(), requestTimeout)
401 defer cancel()
402
403 info, err := dcli.ContainerInspect(ctx, dc.cid())
404 if err != nil {
405 return "", errors.Wrap(err, "error inspecting container")
406 }
407
408 for port, bindings := range info.NetworkSettings.Ports {
409 if len(bindings) == 0 {
410 continue
411 }
412 if port.Port() != privatePort {
413 continue
414 }
415
416 for _, binding := range bindings {
417 if binding.HostIP == "0.0.0.0" {
418 return binding.HostPort, nil
419 }
420 }
421 }
422
423 return "", fmt.Errorf("no mapping found for private port [%v] for container [%v]", privatePort, dc.cname())
424}
425
426// getPortMappingsOnMac parses `docker ps` output to get accurate macOS mappings
427// because docker inspect does not know about port mappings at all.

Callers 11

GetZeroStateURLMethod · 0.85
GetAlphaHttpClientMethod · 0.85
serverURLMethod · 0.85
GetZeroGrpcPublicPortMethod · 0.85
healthURLMethod · 0.85
assignURLMethod · 0.85
zeroURLMethod · 0.85
healthURLMethod · 0.85
alphaURLMethod · 0.85

Calls 4

getPortMappingsOnMacFunction · 0.85
cidMethod · 0.65
cnameMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected