package client

import "github.com/moby/buildkit/util/testutil/dockerd/client"

Index

Constants

const DefaultDockerHost = "unix:///var/run/docker.sock"

DefaultDockerHost defines OS-specific default host if the DOCKER_HOST (EnvOverrideHost) environment variable is unset or empty.

const DefaultVersion = "1.47"

DefaultVersion is the pinned version of the docker API we utilize.

const DummyHost = "api.moby.localhost"

DummyHost is a hostname used for local communication.

It acts as a valid formatted hostname for local connections (such as "unix://" or "npipe://") which do not require a hostname. It should never be resolved, but uses the special-purpose ".localhost" TLD (as defined in RFC 2606, Section 2 and RFC 6761, Section 6.3).

RFC 7230, Section 5.4 defines that an empty header must be used for such cases:

If the authority component is missing or undefined for the target URI,
then a client MUST send a Host header field with an empty field-value.

However, Go stdlib enforces the semantics of HTTP(S) over TCP, does not allow an empty header to be used, and requires req.URL.Scheme to be either "http" or "https".

For further details, refer to:

Variables

var ErrRedirect = errors.New("unexpected redirect in response")

ErrRedirect is the error returned by checkRedirect when the request is non-GET.

Functions

func CheckRedirect

func CheckRedirect(_ *http.Request, via []*http.Request) error

CheckRedirect specifies the policy for dealing with redirect responses. It can be set on http.Client.CheckRedirect to prevent HTTP redirects for non-GET requests. It returns an ErrRedirect for non-GET request, otherwise returns a http.ErrUseLastResponse, which is special-cased by http.Client to use the last response.

Go 1.8 changed behavior for HTTP redirects (specifically 301, 307, and 308) in the client. The client (and by extension API client) can be made to send a request like "POST /containers//start" where what would normally be in the name section of the URL is empty. This triggers an HTTP 301 from the daemon.

In go 1.8 this 301 is converted to a GET request, and ends up getting a 404 from the daemon. This behavior change manifests in the client in that before, the 301 was not followed and the client did not generate an error, but now results in a message like "Error response from daemon: page not found".

func DialPipe

func DialPipe(_ string, _ time.Duration) (net.Conn, error)

DialPipe connects to a Windows named pipe. This is not supported on other OSes.

func ErrorConnectionFailed

func ErrorConnectionFailed(host string) error

ErrorConnectionFailed returns an error with host in the error message when connection to docker daemon failed.

func ParseHostURL

func ParseHostURL(host string) (*url.URL, error)

ParseHostURL parses a url string, validates the string is a host url, and returns the parsed URL

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the API client that performs all operations against a docker server.

func NewClientWithOpts

func NewClientWithOpts(ops ...Opt) (*Client, error)

NewClientWithOpts initializes a new API client with a default HTTPClient, and default API host and version. It also initializes the custom HTTP headers to add to each request.

It takes an optional list of Opt functional arguments, which are applied in the order they're provided, which allows modifying the defaults when creating the client. For example, the following initializes a client that configures itself with values from environment variables ([FromEnv]), and has automatic API version negotiation enabled ([WithAPIVersionNegotiation]).

cli, err := client.NewClientWithOpts(
	client.FromEnv,
	client.WithAPIVersionNegotiation(),
)

func (*Client) Close

func (cli *Client) Close() error

Close the transport used by the client

func (*Client) DialHijack

func (cli *Client) DialHijack(ctx context.Context, url, proto string, meta map[string][]string) (net.Conn, error)

DialHijack returns a hijacked connection with negotiated protocol proto.

func (*Client) Dialer

func (cli *Client) Dialer() func(context.Context) (net.Conn, error)

Dialer returns a dialer for a raw stream connection, with an HTTP/1.1 header, that can be used for proxying the daemon connection. It is used by "docker dial-stdio".

func (*Client) Ping

func (cli *Client) Ping(ctx context.Context) error

type CloseWriter

type CloseWriter interface {
	CloseWrite() error
}

CloseWriter is an interface that implements structs that close input streams to prevent from writing.

type Opt

type Opt func(*Client) error

Opt is a configuration option to initialize a Client.

func WithHost

func WithHost(host string) Opt

WithHost overrides the client host with the specified one.

type PingResponse

type PingResponse struct{}

Source Files

client.go client_unix.go errors.go hijack.go options.go ping.go request.go sockets.go sockets_unix.go

Version
v0.21.0-rc1
Published
Apr 9, 2025
Platform
js/wasm
Imports
15 packages
Last checked
14 seconds ago

Tools for package owners.