func NewDockerDiscovery(conf *DockerSDConfig, logger log.Logger) (*DockerDiscovery, error) {
	var err error

	d := &DockerDiscovery{
		port: conf.Port,
	}

	hostURL, err := url.Parse(conf.Host)
	if err != nil {
		return nil, err
	}

	opts := []client.Opt{
		client.WithHost(conf.Host),
		client.WithAPIVersionNegotiation(),
	}

	d.filters = filters.NewArgs()
	for _, f := range conf.Filters {
		for _, v := range f.Values {
			d.filters.Add(f.Name, v)
		}
	}

	// There are other protocols than HTTP supported by the Docker daemon, like
	// unix, which are not supported by the HTTP client. Passing HTTP client
	// options to the Docker client makes those non-HTTP requests fail.
	if hostURL.Scheme == "http" || hostURL.Scheme == "https" {
		rt, err := config.NewRoundTripperFromConfig(conf.HTTPClientConfig, "docker_sd", false, false)
		if err != nil {
			return nil, err
		}
		opts = append(opts,
			client.WithHTTPClient(&http.Client{
				Transport: rt,
				Timeout:   time.Duration(conf.RefreshInterval),
			}),
			client.WithScheme(hostURL.Scheme),
			client.WithHTTPHeaders(map[string]string{
				"User-Agent": userAgent,
			}),
		)
	}

	d.client, err = client.NewClientWithOpts(opts...)
	if err != nil {
		return nil, fmt.Errorf("error setting up docker client: %w", err)
	}

	d.Discovery = refresh.NewDiscovery(
		logger,
		"docker",
		time.Duration(conf.RefreshInterval),
		d.refresh,
	)
	return d, nil
}
// NewDockerDiscovery returns a new DockerDiscovery which periodically refreshes its targets.
NewDockerDiscovery returns a new DockerDiscovery which periodically refreshes its targets.
// NewDockerDiscovery returns a new DockerDiscovery which periodically refreshes its targets .
func NewDockerDiscovery(conf *DockerSDConfig, logger log.Logger) (*DockerDiscovery, error) {
	var err error
	d := &DockerDiscovery{
		port: conf.Port,
	}
	hostURL, err := url.Parse(conf.Host)
	if err != nil {
		return nil, err
	}
	opts := []client.Opt{
		client.WithHost(conf.Host),
		client.WithAPIVersionNegotiation(),
	}
	d.filters = filters.NewArgs()
	for _, f := range conf.Filters {
		for _, v := range f.Values {
			d.filters.Add(f.Name, v)
		}
	}
	if hostURL.Scheme == "http" || hostURL.Scheme == "https" {
		rt, err := config.NewRoundTripperFromConfig(conf.HTTPClientConfig, "docker_sd", false, false)
		if err != nil {
			return nil, err
		}
		opts = append(opts,
			client.WithHTTPClient(&http.Client{
				Transport: rt,
				Timeout:   time.Duration(conf.RefreshInterval),
			}),
			client.WithScheme(hostURL.Scheme),
			client.WithHTTPHeaders(map[string]string{
				"User-Agent": userAgent,
			}),
		)
	}
	d.client, err = client.NewClientWithOpts(opts...)
	if err != nil {
		return nil, fmt.Errorf("error setting up docker client: %w", err)
	}
	d.Discovery = refresh.NewDiscovery(
		logger,
		"docker",
		time.Duration(conf.RefreshInterval),
		d.refresh,
	)
	return d, nil
}
func NewDockerDiscovery ( conf * DockerSDConfig , logger log . Logger ) ( * DockerDiscovery , error ) { var err error d := & DockerDiscovery { port : conf . Port , } hostURL , err := url . Parse ( conf . Host ) if err != nil { return nil , err } opts := [ ] client . Opt { client . WithHost ( conf . Host ) , client . WithAPIVersionNegotiation ( ) , } d . filters = filters . NewArgs ( ) for _ , f := range conf . Filters { for _ , v := range f . Values { d . filters . Add ( f . Name , v ) } } if hostURL . Scheme == " " || hostURL . Scheme == " " { rt , err := config . NewRoundTripperFromConfig ( conf . HTTPClientConfig , " " , false , false ) if err != nil { return nil , err } opts = append ( opts , client . WithHTTPClient ( & http . Client { Transport : rt , Timeout : time . Duration ( conf . RefreshInterval ) , } ) , client . WithScheme ( hostURL . Scheme ) , client . WithHTTPHeaders ( map [ string ] string { " " : userAgent , } ) , ) } d . client , err = client . NewClientWithOpts ( opts ... ) if err != nil { return nil , fmt . Errorf ( " " , err ) } d . Discovery = refresh . NewDiscovery ( logger , " " , time . Duration ( conf . RefreshInterval ) , d . refresh , ) return d , nil }
NewDockerDiscovery returns a new DockerDiscovery which periodically refreshes its targets.
NewDockerDiscovery returns a new DockerDiscovery which periodically refreshes its targets .
// There are other protocols than HTTP supported by the Docker daemon, like // unix, which are not supported by the HTTP client. Passing HTTP client // options to the Docker client makes those non-HTTP requests fail.