func()

in internal/components/setup/compose_provider.go [317:356]


func (p *DockerProvider) daemonHost(ctx context.Context) (string, error) {
	if p.hostCache != "" {
		return p.hostCache, nil
	}

	host, exists := os.LookupEnv("TC_HOST")
	if exists {
		p.hostCache = host
		return p.hostCache, nil
	}

	// infer from Docker host
	parsedURL, err := url.Parse(p.client.DaemonHost())
	if err != nil {
		return "", err
	}

	switch parsedURL.Scheme {
	case "http", "https", "tcp":
		p.hostCache = parsedURL.Hostname()
	case "unix", "npipe":
		if inAContainer() {
			ip, err := p.GetGatewayIP(ctx)
			if err != nil {
				// fallback to getDefaultGatewayIP
				ip, err = getDefaultGatewayIP()
				if err != nil {
					ip = localhost
				}
			}
			p.hostCache = ip
		} else {
			p.hostCache = localhost
		}
	default:
		return "", errors.New("could not determine host through env or docker host")
	}

	return p.hostCache, nil
}