client

package
v26.1.4+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2024 License: Apache-2.0 Imports: 43 Imported by: 0

README

Go client for the Docker Engine API

The docker command uses this package to communicate with the daemon. It can also be used by your own Go applications to do anything the command-line interface does – running containers, pulling images, managing swarms, etc.

For example, to list all containers (the equivalent of docker ps --all):

package main

import (
	"context"
	"fmt"

	"github.com/docker/docker/api/types/container"
	"github.com/docker/docker/client"
)

func main() {
	apiClient, err := client.NewClientWithOpts(client.FromEnv)
	if err != nil {
		panic(err)
	}
	defer apiClient.Close()

	containers, err := apiClient.ContainerList(context.Background(), container.ListOptions{All: true})
	if err != nil {
		panic(err)
	}

	for _, ctr := range containers {
		fmt.Printf("%s %s (status: %s)\n", ctr.ID, ctr.Image, ctr.Status)
	}
}

Full documentation is available on pkg.go.dev.

Documentation

Overview

Package client is a Go client for the Docker Engine API.

For more information about the Engine API, see the documentation: https://docs.docker.com/engine/api/

Usage

You use the library by constructing a client object using NewClientWithOpts and calling methods on it. The client can be configured from environment variables by passing the FromEnv option, or configured manually by passing any of the other available [Opts].

For example, to list running containers (the equivalent of "docker ps"):

package main

import (
	"context"
	"fmt"

	"github.com/docker/docker/api/types/container"
	"github.com/docker/docker/client"
)

func main() {
	cli, err := client.NewClientWithOpts(client.FromEnv)
	if err != nil {
		panic(err)
	}

	containers, err := cli.ContainerList(context.Background(), container.ListOptions{})
	if err != nil {
		panic(err)
	}

	for _, ctr := range containers {
		fmt.Printf("%s %s\n", ctr.ID, ctr.Image)
	}
}

Index

Examples

Constants

View Source
const (
	// EnvOverrideHost is the name of the environment variable that can be used
	// to override the default host to connect to (DefaultDockerHost).
	//
	// This env-var is read by FromEnv and WithHostFromEnv and when set to a
	// non-empty value, takes precedence over the default host (which is platform
	// specific), or any host already set.
	EnvOverrideHost = "DOCKER_HOST"

	// EnvOverrideAPIVersion is the name of the environment variable that can
	// be used to override the API version to use. Value should be
	// formatted as MAJOR.MINOR, for example, "1.19".
	//
	// This env-var is read by FromEnv and WithVersionFromEnv and when set to a
	// non-empty value, takes precedence over API version negotiation.
	//
	// This environment variable should be used for debugging purposes only, as
	// it can set the client to use an incompatible (or invalid) API version.
	EnvOverrideAPIVersion = "DOCKER_API_VERSION"

	// EnvOverrideCertPath is the name of the environment variable that can be
	// used to specify the directory from which to load the TLS certificates
	// (ca.pem, cert.pem, key.pem) from. These certificates are used to configure
	// the Client for a TCP connection protected by TLS client authentication.
	//
	// TLS certificate verification is enabled by default if the Client is configured
	// to use a TLS connection. Refer to EnvTLSVerify below to learn how to
	// disable verification for testing purposes.
	//
	// WARNING: Access to the remote API is equivalent to root access to the
	// host where the daemon runs. Do not expose the API without protection,
	// and only if needed. Make sure you are familiar with the "daemon attack
	// surface" (https://docs.docker.com/go/attack-surface/).
	//
	// For local access to the API, it is recommended to connect with the daemon
	// using the default local socket connection (on Linux), or the named pipe
	// (on Windows).
	//
	// If you need to access the API of a remote daemon, consider using an SSH
	// (ssh://) connection, which is easier to set up, and requires no additional
	// configuration if the host is accessible using ssh.
	//
	// If you cannot use the alternatives above, and you must expose the API over
	// a TCP connection, refer to https://docs.docker.com/engine/security/protect-access/
	// to learn how to configure the daemon and client to use a TCP connection
	// with TLS client authentication. Make sure you know the differences between
	// a regular TLS connection and a TLS connection protected by TLS client
	// authentication, and verify that the API cannot be accessed by other clients.
	EnvOverrideCertPath = "DOCKER_CERT_PATH"

	// EnvTLSVerify is the name of the environment variable that can be used to
	// enable or disable TLS certificate verification. When set to a non-empty
	// value, TLS certificate verification is enabled, and the client is configured
	// to use a TLS connection, using certificates from the default directories
	// (within `~/.docker`); refer to EnvOverrideCertPath above for additional
	// details.
	//
	// WARNING: Access to the remote API is equivalent to root access to the
	// host where the daemon runs. Do not expose the API without protection,
	// and only if needed. Make sure you are familiar with the "daemon attack
	// surface" (https://docs.docker.com/go/attack-surface/).
	//
	// Before setting up your client and daemon to use a TCP connection with TLS
	// client authentication, consider using one of the alternatives mentioned
	// in EnvOverrideCertPath above.
	//
	// Disabling TLS certificate verification (for testing purposes)
	//
	// TLS certificate verification is enabled by default if the Client is configured
	// to use a TLS connection, and it is highly recommended to keep verification
	// enabled to prevent machine-in-the-middle attacks. Refer to the documentation
	// at https://docs.docker.com/engine/security/protect-access/ and pages linked
	// from that page to learn how to configure the daemon and client to use a
	// TCP connection with TLS client authentication enabled.
	//
	// Set the "DOCKER_TLS_VERIFY" environment to an empty string ("") to
	// disable TLS certificate verification. Disabling verification is insecure,
	// so should only be done for testing purposes. From the Go documentation
	// (https://pkg.go.dev/crypto/tls#Config):
	//
	// InsecureSkipVerify controls whether a client verifies the server's
	// certificate chain and host name. If InsecureSkipVerify is true, crypto/tls
	// accepts any certificate presented by the server and any host name in that
	// certificate. In this mode, TLS is susceptible to machine-in-the-middle
	// attacks unless custom verification is used. This should be used only for
	// testing or in combination with VerifyConnection or VerifyPeerCertificate.
	EnvTLSVerify = "DOCKER_TLS_VERIFY"
)
View Source
const DefaultDockerHost = "unix:///var/run/docker.sock"

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

View Source
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

View Source
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 ErrorConnectionFailed

func ErrorConnectionFailed(host string) error

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

func FromEnv

func FromEnv(c *Client) error

FromEnv configures the client with values from environment variables. It is the equivalent of using the WithTLSClientConfigFromEnv, WithHostFromEnv, and WithVersionFromEnv options.

FromEnv uses the following environment variables:

  • DOCKER_HOST (EnvOverrideHost) to set the URL to the docker server.
  • DOCKER_API_VERSION (EnvOverrideAPIVersion) to set the version of the API to use, leave empty for latest.
  • DOCKER_CERT_PATH (EnvOverrideCertPath) to specify the directory from which to load the TLS certificates ("ca.pem", "cert.pem", "key.pem').
  • DOCKER_TLS_VERIFY (EnvTLSVerify) to enable or disable TLS verification (off by default).

func IsErrConnectionFailed

func IsErrConnectionFailed(err error) bool

IsErrConnectionFailed returns true if the error is caused by connection failed.

func IsErrNotFound

func IsErrNotFound(err error) bool

IsErrNotFound returns true if the error is a NotFound error, which is returned by the API when some object is not found. It is an alias for errdefs.IsNotFound.

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 APIClient

type APIClient interface {
	CommonAPIClient
	// contains filtered or unexported methods
}

APIClient is an interface that clients that talk with a docker server must implement.

type CheckpointAPIClient

type CheckpointAPIClient interface {
	CheckpointCreate(ctx context.Context, container string, options checkpoint.CreateOptions) error
	CheckpointDelete(ctx context.Context, container string, options checkpoint.DeleteOptions) error
	CheckpointList(ctx context.Context, container string, options checkpoint.ListOptions) ([]checkpoint.Summary, error)
}

CheckpointAPIClient defines API client methods for the checkpoints

type Client

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

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

func NewClient deprecated

func NewClient(host string, version string, client *http.Client, httpHeaders map[string]string) (*Client, error)

NewClient initializes a new API client for the given host and API version. It uses the given http client as transport. It also initializes the custom http headers to add to each request.

It won't send any version information if the version number is empty. It is highly recommended that you set a version or your client may break if the server is upgraded.

Deprecated: use NewClientWithOpts passing the WithHost, WithVersion, WithHTTPClient and WithHTTPHeaders options. We recommend enabling API version negotiation by passing the WithAPIVersionNegotiation option instead of WithVersion.

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 NewEnvClient deprecated

func NewEnvClient() (*Client, error)

NewEnvClient initializes a new API client based on environment variables. See FromEnv for a list of support environment variables.

Deprecated: use NewClientWithOpts passing the FromEnv option.

func (*Client) BuildCachePrune

func (cli *Client) BuildCachePrune(ctx context.Context, opts types.BuildCachePruneOptions) (*types.BuildCachePruneReport, error)

BuildCachePrune requests the daemon to delete unused cache data

func (*Client) BuildCancel

func (cli *Client) BuildCancel(ctx context.Context, id string) error

BuildCancel requests the daemon to cancel the ongoing build request.

func (*Client) CheckpointCreate

func (cli *Client) CheckpointCreate(ctx context.Context, container string, options checkpoint.CreateOptions) error

CheckpointCreate creates a checkpoint from the given container with the given name

func (*Client) CheckpointDelete

func (cli *Client) CheckpointDelete(ctx context.Context, containerID string, options checkpoint.DeleteOptions) error

CheckpointDelete deletes the checkpoint with the given name from the given container

func (*Client) CheckpointList

func (cli *Client) CheckpointList(ctx context.Context, container string, options checkpoint.ListOptions) ([]checkpoint.Summary, error)

CheckpointList returns the checkpoints of the given container in the docker host

func (*Client) ClientVersion

func (cli *Client) ClientVersion() string

ClientVersion returns the API version used by this client.

func (*Client) Close

func (cli *Client) Close() error

Close the transport used by the client

func (*Client) ConfigCreate

func (cli *Client) ConfigCreate(ctx context.Context, config swarm.ConfigSpec) (types.ConfigCreateResponse, error)

ConfigCreate creates a new config.

func (*Client) ConfigInspectWithRaw

func (cli *Client) ConfigInspectWithRaw(ctx context.Context, id string) (swarm.Config, []byte, error)

ConfigInspectWithRaw returns the config information with raw data

func (*Client) ConfigList

func (cli *Client) ConfigList(ctx context.Context, options types.ConfigListOptions) ([]swarm.Config, error)

ConfigList returns the list of configs.

func (*Client) ConfigRemove

func (cli *Client) ConfigRemove(ctx context.Context, id string) error

ConfigRemove removes a config.

func (*Client) ConfigUpdate

func (cli *Client) ConfigUpdate(ctx context.Context, id string, version swarm.Version, config swarm.ConfigSpec) error

ConfigUpdate attempts to update a config

func (*Client) ContainerAttach

func (cli *Client) ContainerAttach(ctx context.Context, container string, options container.AttachOptions) (types.HijackedResponse, error)

ContainerAttach attaches a connection to a container in the server. It returns a types.HijackedConnection with the hijacked connection and the a reader to get output. It's up to the called to close the hijacked connection by calling types.HijackedResponse.Close.

The stream format on the response will be in one of two formats:

If the container is using a TTY, there is only a single stream (stdout), and data is copied directly from the container output stream, no extra multiplexing or headers.

If the container is *not* using a TTY, streams for stdout and stderr are multiplexed. The format of the multiplexed stream is as follows:

[8]byte{STREAM_TYPE, 0, 0, 0, SIZE1, SIZE2, SIZE3, SIZE4}[]byte{OUTPUT}

STREAM_TYPE can be 1 for stdout and 2 for stderr

SIZE1, SIZE2, SIZE3, and SIZE4 are four bytes of uint32 encoded as big endian. This is the size of OUTPUT.

You can use github.com/docker/docker/pkg/stdcopy.StdCopy to demultiplex this stream.

func (*Client) ContainerCommit

func (cli *Client) ContainerCommit(ctx context.Context, container string, options container.CommitOptions) (types.IDResponse, error)

ContainerCommit applies changes to a container and creates a new tagged image.

func (*Client) ContainerCreate

func (cli *Client) ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *ocispec.Platform, containerName string) (container.CreateResponse, error)

ContainerCreate creates a new container based on the given configuration. It can be associated with a name, but it's not mandatory.

func (*Client) ContainerDiff

func (cli *Client) ContainerDiff(ctx context.Context, containerID string) ([]container.FilesystemChange, error)

ContainerDiff shows differences in a container filesystem since it was started.

func (*Client) ContainerExecAttach

func (cli *Client) ContainerExecAttach(ctx context.Context, execID string, config types.ExecStartCheck) (types.HijackedResponse, error)

ContainerExecAttach attaches a connection to an exec process in the server. It returns a types.HijackedConnection with the hijacked connection and the a reader to get output. It's up to the called to close the hijacked connection by calling types.HijackedResponse.Close.

func (*Client) ContainerExecCreate

func (cli *Client) ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error)

ContainerExecCreate creates a new exec configuration to run an exec process.

func (*Client) ContainerExecInspect

func (cli *Client) ContainerExecInspect(ctx context.Context, execID string) (types.ContainerExecInspect, error)

ContainerExecInspect returns information about a specific exec process on the docker host.

func (*Client) ContainerExecResize

func (cli *Client) ContainerExecResize(ctx context.Context, execID string, options container.ResizeOptions) error

ContainerExecResize changes the size of the tty for an exec process running inside a container.

func (*Client) ContainerExecStart

func (cli *Client) ContainerExecStart(ctx context.Context, execID string, config types.ExecStartCheck) error

ContainerExecStart starts an exec process already created in the docker host.

func (*Client) ContainerExport

func (cli *Client) ContainerExport(ctx context.Context, containerID string) (io.ReadCloser, error)

ContainerExport retrieves the raw contents of a container and returns them as an io.ReadCloser. It's up to the caller to close the stream.

func (*Client) ContainerInspect

func (cli *Client) ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error)

ContainerInspect returns the container information.

func (*Client) ContainerInspectWithRaw

func (cli *Client) ContainerInspectWithRaw(ctx context.Context, containerID string, getSize bool) (types.ContainerJSON, []byte, error)

ContainerInspectWithRaw returns the container information and its raw representation.

func (*Client) ContainerKill

func (cli *Client) ContainerKill(ctx context.Context, containerID, signal string) error

ContainerKill terminates the container process but does not remove the container from the docker host.

func (*Client) ContainerList

func (cli *Client) ContainerList(ctx context.Context, options container.ListOptions) ([]types.Container, error)

ContainerList returns the list of containers in the docker host.

func (*Client) ContainerLogs

func (cli *Client) ContainerLogs(ctx context.Context, container string, options container.LogsOptions) (io.ReadCloser, error)

ContainerLogs returns the logs generated by a container in an io.ReadCloser. It's up to the caller to close the stream.

The stream format on the response will be in one of two formats:

If the container is using a TTY, there is only a single stream (stdout), and data is copied directly from the container output stream, no extra multiplexing or headers.

If the container is *not* using a TTY, streams for stdout and stderr are multiplexed. The format of the multiplexed stream is as follows:

[8]byte{STREAM_TYPE, 0, 0, 0, SIZE1, SIZE2, SIZE3, SIZE4}[]byte{OUTPUT}

STREAM_TYPE can be 1 for stdout and 2 for stderr

SIZE1, SIZE2, SIZE3, and SIZE4 are four bytes of uint32 encoded as big endian. This is the size of OUTPUT.

You can use github.com/docker/docker/pkg/stdcopy.StdCopy to demultiplex this stream.

Example (WithTimeout)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

client, _ := NewClientWithOpts(FromEnv)
reader, err := client.ContainerLogs(ctx, "container_id", container.LogsOptions{})
if err != nil {
	log.Fatal(err)
}

_, err = io.Copy(os.Stdout, reader)
if err != nil && err != io.EOF {
	log.Fatal(err)
}
Output:

func (*Client) ContainerPause

func (cli *Client) ContainerPause(ctx context.Context, containerID string) error

ContainerPause pauses the main process of a given container without terminating it.

func (*Client) ContainerRemove

func (cli *Client) ContainerRemove(ctx context.Context, containerID string, options container.RemoveOptions) error

ContainerRemove kills and removes a container from the docker host.

func (*Client) ContainerRename

func (cli *Client) ContainerRename(ctx context.Context, containerID, newContainerName string) error

ContainerRename changes the name of a given container.

func (*Client) ContainerResize

func (cli *Client) ContainerResize(ctx context.Context, containerID string, options container.ResizeOptions) error

ContainerResize changes the size of the tty for a container.

func (*Client) ContainerRestart

func (cli *Client) ContainerRestart(ctx context.Context, containerID string, options container.StopOptions) error

ContainerRestart stops and starts a container again. It makes the daemon wait for the container to be up again for a specific amount of time, given the timeout.

func (*Client) ContainerStart

func (cli *Client) ContainerStart(ctx context.Context, containerID string, options container.StartOptions) error

ContainerStart sends a request to the docker daemon to start a container.

func (*Client) ContainerStatPath

func (cli *Client) ContainerStatPath(ctx context.Context, containerID, path string) (types.ContainerPathStat, error)

ContainerStatPath returns stat information about a path inside the container filesystem.

func (*Client) ContainerStats

func (cli *Client) ContainerStats(ctx context.Context, containerID string, stream bool) (types.ContainerStats, error)

ContainerStats returns near realtime stats for a given container. It's up to the caller to close the io.ReadCloser returned.

func (*Client) ContainerStatsOneShot

func (cli *Client) ContainerStatsOneShot(ctx context.Context, containerID string) (types.ContainerStats, error)

ContainerStatsOneShot gets a single stat entry from a container. It differs from `ContainerStats` in that the API should not wait to prime the stats

func (*Client) ContainerStop

func (cli *Client) ContainerStop(ctx context.Context, containerID string, options container.StopOptions) error

ContainerStop stops a container. In case the container fails to stop gracefully within a time frame specified by the timeout argument, it is forcefully terminated (killed).

If the timeout is nil, the container's StopTimeout value is used, if set, otherwise the engine default. A negative timeout value can be specified, meaning no timeout, i.e. no forceful termination is performed.

func (*Client) ContainerTop

func (cli *Client) ContainerTop(ctx context.Context, containerID string, arguments []string) (container.ContainerTopOKBody, error)

ContainerTop shows process information from within a container.

func (*Client) ContainerUnpause

func (cli *Client) ContainerUnpause(ctx context.Context, containerID string) error

ContainerUnpause resumes the process execution within a container

func (*Client) ContainerUpdate

func (cli *Client) ContainerUpdate(ctx context.Context, containerID string, updateConfig container.UpdateConfig) (container.ContainerUpdateOKBody, error)

ContainerUpdate updates the resources of a container.

func (*Client) ContainerWait

func (cli *Client) ContainerWait(ctx context.Context, containerID string, condition container.WaitCondition) (<-chan container.WaitResponse, <-chan error)

ContainerWait waits until the specified container is in a certain state indicated by the given condition, either "not-running" (default), "next-exit", or "removed".

If this client's API version is before 1.30, condition is ignored and ContainerWait will return immediately with the two channels, as the server will wait as if the condition were "not-running".

If this client's API version is at least 1.30, ContainerWait blocks until the request has been acknowledged by the server (with a response header), then returns two channels on which the caller can wait for the exit status of the container or an error if there was a problem either beginning the wait request or in getting the response. This allows the caller to synchronize ContainerWait with other calls, such as specifying a "next-exit" condition before issuing a ContainerStart request.

Example (WithTimeout)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

client, _ := NewClientWithOpts(FromEnv)
_, errC := client.ContainerWait(ctx, "container_id", "")
if err := <-errC; err != nil {
	log.Fatal(err)
}
Output:

func (*Client) ContainersPrune

func (cli *Client) ContainersPrune(ctx context.Context, pruneFilters filters.Args) (types.ContainersPruneReport, error)

ContainersPrune requests the daemon to delete unused data

func (*Client) CopyFromContainer

func (cli *Client) CopyFromContainer(ctx context.Context, containerID, srcPath string) (io.ReadCloser, types.ContainerPathStat, error)

CopyFromContainer gets the content from the container and returns it as a Reader for a TAR archive to manipulate it in the host. It's up to the caller to close the reader.

func (*Client) CopyToContainer

func (cli *Client) CopyToContainer(ctx context.Context, containerID, dstPath string, content io.Reader, options types.CopyToContainerOptions) error

CopyToContainer copies content into the container filesystem. Note that `content` must be a Reader for a TAR archive

func (*Client) DaemonHost

func (cli *Client) DaemonHost() string

DaemonHost returns the host address 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) DiskUsage

func (cli *Client) DiskUsage(ctx context.Context, options types.DiskUsageOptions) (types.DiskUsage, error)

DiskUsage requests the current data usage from the daemon

func (*Client) DistributionInspect

func (cli *Client) DistributionInspect(ctx context.Context, imageRef, encodedRegistryAuth string) (registry.DistributionInspect, error)

DistributionInspect returns the image digest with the full manifest.

func (*Client) Events

func (cli *Client) Events(ctx context.Context, options types.EventsOptions) (<-chan events.Message, <-chan error)

Events returns a stream of events in the daemon. It's up to the caller to close the stream by cancelling the context. Once the stream has been completely read an io.EOF error will be sent over the error channel. If an error is sent all processing will be stopped. It's up to the caller to reopen the stream in the event of an error by reinvoking this method.

func (*Client) HTTPClient

func (cli *Client) HTTPClient() *http.Client

HTTPClient returns a copy of the HTTP client bound to the server

func (*Client) ImageBuild

func (cli *Client) ImageBuild(ctx context.Context, buildContext io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error)

ImageBuild sends a request to the daemon to build images. The Body in the response implements an io.ReadCloser and it's up to the caller to close it.

func (*Client) ImageCreate

func (cli *Client) ImageCreate(ctx context.Context, parentReference string, options image.CreateOptions) (io.ReadCloser, error)

ImageCreate creates a new image based on the parent options. It returns the JSON content in the response body.

func (*Client) ImageHistory

func (cli *Client) ImageHistory(ctx context.Context, imageID string) ([]image.HistoryResponseItem, error)

ImageHistory returns the changes in an image in history format.

func (*Client) ImageImport

func (cli *Client) ImageImport(ctx context.Context, source types.ImageImportSource, ref string, options image.ImportOptions) (io.ReadCloser, error)

ImageImport creates a new image based on the source options. It returns the JSON content in the response body.

func (*Client) ImageInspectWithRaw

func (cli *Client) ImageInspectWithRaw(ctx context.Context, imageID string) (types.ImageInspect, []byte, error)

ImageInspectWithRaw returns the image information and its raw representation.

func (*Client) ImageList

func (cli *Client) ImageList(ctx context.Context, options image.ListOptions) ([]image.Summary, error)

ImageList returns a list of images in the docker host.

func (*Client) ImageLoad

func (cli *Client) ImageLoad(ctx context.Context, input io.Reader, quiet bool) (types.ImageLoadResponse, error)

ImageLoad loads an image in the docker host from the client host. It's up to the caller to close the io.ReadCloser in the ImageLoadResponse returned by this function.

func (*Client) ImagePull

func (cli *Client) ImagePull(ctx context.Context, refStr string, options image.PullOptions) (io.ReadCloser, error)

ImagePull requests the docker host to pull an image from a remote registry. It executes the privileged function if the operation is unauthorized and it tries one more time. It's up to the caller to handle the io.ReadCloser and close it properly.

FIXME(vdemeester): there is currently used in a few way in docker/docker - if not in trusted content, ref is used to pass the whole reference, and tag is empty - if in trusted content, ref is used to pass the reference name, and tag for the digest

func (*Client) ImagePush

func (cli *Client) ImagePush(ctx context.Context, image string, options image.PushOptions) (io.ReadCloser, error)

ImagePush requests the docker host to push an image to a remote registry. It executes the privileged function if the operation is unauthorized and it tries one more time. It's up to the caller to handle the io.ReadCloser and close it properly.

func (*Client) ImageRemove

func (cli *Client) ImageRemove(ctx context.Context, imageID string, options image.RemoveOptions) ([]image.DeleteResponse, error)

ImageRemove removes an image from the docker host.

func (*Client) ImageSave

func (cli *Client) ImageSave(ctx context.Context, imageIDs []string) (io.ReadCloser, error)

ImageSave retrieves one or more images from the docker host as an io.ReadCloser. It's up to the caller to store the images and close the stream.

func (*Client) ImageSearch

func (cli *Client) ImageSearch(ctx context.Context, term string, options types.ImageSearchOptions) ([]registry.SearchResult, error)

ImageSearch makes the docker host search by a term in a remote registry. The list of results is not sorted in any fashion.

func (*Client) ImageTag

func (cli *Client) ImageTag(ctx context.Context, source, target string) error

ImageTag tags an image in the docker host

func (*Client) ImagesPrune

func (cli *Client) ImagesPrune(ctx context.Context, pruneFilters filters.Args) (types.ImagesPruneReport, error)

ImagesPrune requests the daemon to delete unused data

func (*Client) Info

func (cli *Client) Info(ctx context.Context) (system.Info, error)

Info returns information about the docker server.

func (*Client) NegotiateAPIVersion

func (cli *Client) NegotiateAPIVersion(ctx context.Context)

NegotiateAPIVersion queries the API and updates the version to match the API version. NegotiateAPIVersion downgrades the client's API version to match the APIVersion if the ping version is lower than the default version. If the API version reported by the server is higher than the maximum version supported by the client, it uses the client's maximum version.

If a manual override is in place, either through the "DOCKER_API_VERSION" (EnvOverrideAPIVersion) environment variable, or if the client is initialized with a fixed version (WithVersion), no negotiation is performed.

If the API server's ping response does not contain an API version, or if the client did not get a successful ping response, it assumes it is connected with an old daemon that does not support API version negotiation, in which case it downgrades to the latest version of the API before version negotiation was added (1.24).

func (*Client) NegotiateAPIVersionPing

func (cli *Client) NegotiateAPIVersionPing(pingResponse types.Ping)

NegotiateAPIVersionPing downgrades the client's API version to match the APIVersion in the ping response. If the API version in pingResponse is higher than the maximum version supported by the client, it uses the client's maximum version.

If a manual override is in place, either through the "DOCKER_API_VERSION" (EnvOverrideAPIVersion) environment variable, or if the client is initialized with a fixed version (WithVersion), no negotiation is performed.

If the API server's ping response does not contain an API version, we assume we are connected with an old daemon without API version negotiation support, and downgrade to the latest version of the API before version negotiation was added (1.24).

func (*Client) NetworkConnect

func (cli *Client) NetworkConnect(ctx context.Context, networkID, containerID string, config *network.EndpointSettings) error

NetworkConnect connects a container to an existent network in the docker host.

func (*Client) NetworkCreate

func (cli *Client) NetworkCreate(ctx context.Context, name string, options types.NetworkCreate) (types.NetworkCreateResponse, error)

NetworkCreate creates a new network in the docker host.

func (*Client) NetworkDisconnect

func (cli *Client) NetworkDisconnect(ctx context.Context, networkID, containerID string, force bool) error

NetworkDisconnect disconnects a container from an existent network in the docker host.

func (*Client) NetworkInspect

func (cli *Client) NetworkInspect(ctx context.Context, networkID string, options types.NetworkInspectOptions) (types.NetworkResource, error)

NetworkInspect returns the information for a specific network configured in the docker host.

func (*Client) NetworkInspectWithRaw

func (cli *Client) NetworkInspectWithRaw(ctx context.Context, networkID string, options types.NetworkInspectOptions) (types.NetworkResource, []byte, error)

NetworkInspectWithRaw returns the information for a specific network configured in the docker host and its raw representation.

func (*Client) NetworkList

func (cli *Client) NetworkList(ctx context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error)

NetworkList returns the list of networks configured in the docker host.

func (*Client) NetworkRemove

func (cli *Client) NetworkRemove(ctx context.Context, networkID string) error

NetworkRemove removes an existent network from the docker host.

func (*Client) NetworksPrune

func (cli *Client) NetworksPrune(ctx context.Context, pruneFilters filters.Args) (types.NetworksPruneReport, error)

NetworksPrune requests the daemon to delete unused networks

func (*Client) NewVersionError

func (cli *Client) NewVersionError(ctx context.Context, APIrequired, feature string) error

NewVersionError returns an error if the APIVersion required is less than the current supported version.

It performs API-version negotiation if the Client is configured with this option, otherwise it assumes the latest API version is used.

func (*Client) NodeInspectWithRaw

func (cli *Client) NodeInspectWithRaw(ctx context.Context, nodeID string) (swarm.Node, []byte, error)

NodeInspectWithRaw returns the node information.

func (*Client) NodeList

func (cli *Client) NodeList(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error)

NodeList returns the list of nodes.

func (*Client) NodeRemove

func (cli *Client) NodeRemove(ctx context.Context, nodeID string, options types.NodeRemoveOptions) error

NodeRemove removes a Node.

func (*Client) NodeUpdate

func (cli *Client) NodeUpdate(ctx context.Context, nodeID string, version swarm.Version, node swarm.NodeSpec) error

NodeUpdate updates a Node.

func (*Client) Ping

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

Ping pings the server and returns the value of the "Docker-Experimental", "Builder-Version", "OS-Type" & "API-Version" headers. It attempts to use a HEAD request on the endpoint, but falls back to GET if HEAD is not supported by the daemon. It ignores internal server errors returned by the API, which may be returned if the daemon is in an unhealthy state, but returns errors for other non-success status codes, failing to connect to the API, or failing to parse the API response.

func (*Client) PluginCreate

func (cli *Client) PluginCreate(ctx context.Context, createContext io.Reader, createOptions types.PluginCreateOptions) error

PluginCreate creates a plugin

func (*Client) PluginDisable

func (cli *Client) PluginDisable(ctx context.Context, name string, options types.PluginDisableOptions) error

PluginDisable disables a plugin

func (*Client) PluginEnable

func (cli *Client) PluginEnable(ctx context.Context, name string, options types.PluginEnableOptions) error

PluginEnable enables a plugin

func (*Client) PluginInspectWithRaw

func (cli *Client) PluginInspectWithRaw(ctx context.Context, name string) (*types.Plugin, []byte, error)

PluginInspectWithRaw inspects an existing plugin

func (*Client) PluginInstall

func (cli *Client) PluginInstall(ctx context.Context, name string, options types.PluginInstallOptions) (rc io.ReadCloser, err error)

PluginInstall installs a plugin

func (*Client) PluginList

func (cli *Client) PluginList(ctx context.Context, filter filters.Args) (types.PluginsListResponse, error)

PluginList returns the installed plugins

func (*Client) PluginPush

func (cli *Client) PluginPush(ctx context.Context, name string, registryAuth string) (io.ReadCloser, error)

PluginPush pushes a plugin to a registry

func (*Client) PluginRemove

func (cli *Client) PluginRemove(ctx context.Context, name string, options types.PluginRemoveOptions) error

PluginRemove removes a plugin

func (*Client) PluginSet

func (cli *Client) PluginSet(ctx context.Context, name string, args []string) error

PluginSet modifies settings for an existing plugin

func (*Client) PluginUpgrade

func (cli *Client) PluginUpgrade(ctx context.Context, name string, options types.PluginInstallOptions) (rc io.ReadCloser, err error)

PluginUpgrade upgrades a plugin

func (*Client) RegistryLogin

func (cli *Client) RegistryLogin(ctx context.Context, auth registry.AuthConfig) (registry.AuthenticateOKBody, error)

RegistryLogin authenticates the docker server with a given docker registry. It returns unauthorizedError when the authentication fails.

func (*Client) SecretCreate

func (cli *Client) SecretCreate(ctx context.Context, secret swarm.SecretSpec) (types.SecretCreateResponse, error)

SecretCreate creates a new secret.

func (*Client) SecretInspectWithRaw

func (cli *Client) SecretInspectWithRaw(ctx context.Context, id string) (swarm.Secret, []byte, error)

SecretInspectWithRaw returns the secret information with raw data

func (*Client) SecretList

func (cli *Client) SecretList(ctx context.Context, options types.SecretListOptions) ([]swarm.Secret, error)

SecretList returns the list of secrets.

func (*Client) SecretRemove

func (cli *Client) SecretRemove(ctx context.Context, id string) error

SecretRemove removes a secret.

func (*Client) SecretUpdate

func (cli *Client) SecretUpdate(ctx context.Context, id string, version swarm.Version, secret swarm.SecretSpec) error

SecretUpdate attempts to update a secret.

func (*Client) ServerVersion

func (cli *Client) ServerVersion(ctx context.Context) (types.Version, error)

ServerVersion returns information of the docker client and server host.

func (*Client) ServiceCreate

func (cli *Client) ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options types.ServiceCreateOptions) (swarm.ServiceCreateResponse, error)

ServiceCreate creates a new service.

func (*Client) ServiceInspectWithRaw

func (cli *Client) ServiceInspectWithRaw(ctx context.Context, serviceID string, opts types.ServiceInspectOptions) (swarm.Service, []byte, error)

ServiceInspectWithRaw returns the service information and the raw data.

func (*Client) ServiceList

func (cli *Client) ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error)

ServiceList returns the list of services.

func (*Client) ServiceLogs

func (cli *Client) ServiceLogs(ctx context.Context, serviceID string, options container.LogsOptions) (io.ReadCloser, error)

ServiceLogs returns the logs generated by a service in an io.ReadCloser. It's up to the caller to close the stream.

Example (WithTimeout)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

client, _ := NewClientWithOpts(FromEnv)
reader, err := client.ServiceLogs(ctx, "service_id", container.LogsOptions{})
if err != nil {
	log.Fatal(err)
}

_, err = io.Copy(os.Stdout, reader)
if err != nil && err != io.EOF {
	log.Fatal(err)
}
Output:

func (*Client) ServiceRemove

func (cli *Client) ServiceRemove(ctx context.Context, serviceID string) error

ServiceRemove kills and removes a service.

func (*Client) ServiceUpdate

func (cli *Client) ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error)

ServiceUpdate updates a Service. The version number is required to avoid conflicting writes. It should be the value as set *before* the update. You can find this value in the Meta field of swarm.Service, which can be found using ServiceInspectWithRaw.

func (*Client) SwarmGetUnlockKey

func (cli *Client) SwarmGetUnlockKey(ctx context.Context) (types.SwarmUnlockKeyResponse, error)

SwarmGetUnlockKey retrieves the swarm's unlock key.

func (*Client) SwarmInit

func (cli *Client) SwarmInit(ctx context.Context, req swarm.InitRequest) (string, error)

SwarmInit initializes the swarm.

func (*Client) SwarmInspect

func (cli *Client) SwarmInspect(ctx context.Context) (swarm.Swarm, error)

SwarmInspect inspects the swarm.

func (*Client) SwarmJoin

func (cli *Client) SwarmJoin(ctx context.Context, req swarm.JoinRequest) error

SwarmJoin joins the swarm.

func (*Client) SwarmLeave

func (cli *Client) SwarmLeave(ctx context.Context, force bool) error

SwarmLeave leaves the swarm.

func (*Client) SwarmUnlock

func (cli *Client) SwarmUnlock(ctx context.Context, req swarm.UnlockRequest) error

SwarmUnlock unlocks locked swarm.

func (*Client) SwarmUpdate

func (cli *Client) SwarmUpdate(ctx context.Context, version swarm.Version, swarm swarm.Spec, flags swarm.UpdateFlags) error

SwarmUpdate updates the swarm.

func (*Client) TaskInspectWithRaw

func (cli *Client) TaskInspectWithRaw(ctx context.Context, taskID string) (swarm.Task, []byte, error)

TaskInspectWithRaw returns the task information and its raw representation.

func (*Client) TaskList

func (cli *Client) TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error)

TaskList returns the list of tasks.

func (*Client) TaskLogs

func (cli *Client) TaskLogs(ctx context.Context, taskID string, options container.LogsOptions) (io.ReadCloser, error)

TaskLogs returns the logs generated by a task in an io.ReadCloser. It's up to the caller to close the stream.

func (*Client) VolumeCreate

func (cli *Client) VolumeCreate(ctx context.Context, options volume.CreateOptions) (volume.Volume, error)

VolumeCreate creates a volume in the docker host.

func (*Client) VolumeInspect

func (cli *Client) VolumeInspect(ctx context.Context, volumeID string) (volume.Volume, error)

VolumeInspect returns the information about a specific volume in the docker host.

func (*Client) VolumeInspectWithRaw

func (cli *Client) VolumeInspectWithRaw(ctx context.Context, volumeID string) (volume.Volume, []byte, error)

VolumeInspectWithRaw returns the information about a specific volume in the docker host and its raw representation

func (*Client) VolumeList

func (cli *Client) VolumeList(ctx context.Context, options volume.ListOptions) (volume.ListResponse, error)

VolumeList returns the volumes configured in the docker host.

func (*Client) VolumeRemove

func (cli *Client) VolumeRemove(ctx context.Context, volumeID string, force bool) error

VolumeRemove removes a volume from the docker host.

func (*Client) VolumeUpdate

func (cli *Client) VolumeUpdate(ctx context.Context, volumeID string, version swarm.Version, options volume.UpdateOptions) error

VolumeUpdate updates a volume. This only works for Cluster Volumes, and only some fields can be updated.

func (*Client) VolumesPrune

func (cli *Client) VolumesPrune(ctx context.Context, pruneFilters filters.Args) (types.VolumesPruneReport, error)

VolumesPrune requests the daemon to delete unused data

type CommonAPIClient

type CommonAPIClient interface {
	ConfigAPIClient
	ContainerAPIClient
	DistributionAPIClient
	ImageAPIClient
	NodeAPIClient
	NetworkAPIClient
	PluginAPIClient
	ServiceAPIClient
	SwarmAPIClient
	SecretAPIClient
	SystemAPIClient
	VolumeAPIClient
	ClientVersion() string
	DaemonHost() string
	HTTPClient() *http.Client
	ServerVersion(ctx context.Context) (types.Version, error)
	NegotiateAPIVersion(ctx context.Context)
	NegotiateAPIVersionPing(types.Ping)
	DialHijack(ctx context.Context, url, proto string, meta map[string][]string) (net.Conn, error)
	Dialer() func(context.Context) (net.Conn, error)
	Close() error
}

CommonAPIClient is the common methods between stable and experimental versions of APIClient.

type ConfigAPIClient

type ConfigAPIClient interface {
	ConfigList(ctx context.Context, options types.ConfigListOptions) ([]swarm.Config, error)
	ConfigCreate(ctx context.Context, config swarm.ConfigSpec) (types.ConfigCreateResponse, error)
	ConfigRemove(ctx context.Context, id string) error
	ConfigInspectWithRaw(ctx context.Context, name string) (swarm.Config, []byte, error)
	ConfigUpdate(ctx context.Context, id string, version swarm.Version, config swarm.ConfigSpec) error
}

ConfigAPIClient defines API client methods for configs

type ContainerAPIClient

type ContainerAPIClient interface {
	ContainerAttach(ctx context.Context, container string, options container.AttachOptions) (types.HijackedResponse, error)
	ContainerCommit(ctx context.Context, container string, options container.CommitOptions) (types.IDResponse, error)
	ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *ocispec.Platform, containerName string) (container.CreateResponse, error)
	ContainerDiff(ctx context.Context, container string) ([]container.FilesystemChange, error)
	ContainerExecAttach(ctx context.Context, execID string, config types.ExecStartCheck) (types.HijackedResponse, error)
	ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error)
	ContainerExecInspect(ctx context.Context, execID string) (types.ContainerExecInspect, error)
	ContainerExecResize(ctx context.Context, execID string, options container.ResizeOptions) error
	ContainerExecStart(ctx context.Context, execID string, config types.ExecStartCheck) error
	ContainerExport(ctx context.Context, container string) (io.ReadCloser, error)
	ContainerInspect(ctx context.Context, container string) (types.ContainerJSON, error)
	ContainerInspectWithRaw(ctx context.Context, container string, getSize bool) (types.ContainerJSON, []byte, error)
	ContainerKill(ctx context.Context, container, signal string) error
	ContainerList(ctx context.Context, options container.ListOptions) ([]types.Container, error)
	ContainerLogs(ctx context.Context, container string, options container.LogsOptions) (io.ReadCloser, error)
	ContainerPause(ctx context.Context, container string) error
	ContainerRemove(ctx context.Context, container string, options container.RemoveOptions) error
	ContainerRename(ctx context.Context, container, newContainerName string) error
	ContainerResize(ctx context.Context, container string, options container.ResizeOptions) error
	ContainerRestart(ctx context.Context, container string, options container.StopOptions) error
	ContainerStatPath(ctx context.Context, container, path string) (types.ContainerPathStat, error)
	ContainerStats(ctx context.Context, container string, stream bool) (types.ContainerStats, error)
	ContainerStatsOneShot(ctx context.Context, container string) (types.ContainerStats, error)
	ContainerStart(ctx context.Context, container string, options container.StartOptions) error
	ContainerStop(ctx context.Context, container string, options container.StopOptions) error
	ContainerTop(ctx context.Context, container string, arguments []string) (container.ContainerTopOKBody, error)
	ContainerUnpause(ctx context.Context, container string) error
	ContainerUpdate(ctx context.Context, container string, updateConfig container.UpdateConfig) (container.ContainerUpdateOKBody, error)
	ContainerWait(ctx context.Context, container string, condition container.WaitCondition) (<-chan container.WaitResponse, <-chan error)
	CopyFromContainer(ctx context.Context, container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error)
	CopyToContainer(ctx context.Context, container, path string, content io.Reader, options types.CopyToContainerOptions) error
	ContainersPrune(ctx context.Context, pruneFilters filters.Args) (types.ContainersPruneReport, error)
}

ContainerAPIClient defines API client methods for the containers

type DistributionAPIClient

type DistributionAPIClient interface {
	DistributionInspect(ctx context.Context, image, encodedRegistryAuth string) (registry.DistributionInspect, error)
}

DistributionAPIClient defines API client methods for the registry

type ImageAPIClient

type ImageAPIClient interface {
	ImageBuild(ctx context.Context, context io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error)
	BuildCachePrune(ctx context.Context, opts types.BuildCachePruneOptions) (*types.BuildCachePruneReport, error)
	BuildCancel(ctx context.Context, id string) error
	ImageCreate(ctx context.Context, parentReference string, options image.CreateOptions) (io.ReadCloser, error)
	ImageHistory(ctx context.Context, image string) ([]image.HistoryResponseItem, error)
	ImageImport(ctx context.Context, source types.ImageImportSource, ref string, options image.ImportOptions) (io.ReadCloser, error)
	ImageInspectWithRaw(ctx context.Context, image string) (types.ImageInspect, []byte, error)
	ImageList(ctx context.Context, options image.ListOptions) ([]image.Summary, error)
	ImageLoad(ctx context.Context, input io.Reader, quiet bool) (types.ImageLoadResponse, error)
	ImagePull(ctx context.Context, ref string, options image.PullOptions) (io.ReadCloser, error)
	ImagePush(ctx context.Context, ref string, options image.PushOptions) (io.ReadCloser, error)
	ImageRemove(ctx context.Context, image string, options image.RemoveOptions) ([]image.DeleteResponse, error)
	ImageSearch(ctx context.Context, term string, options types.ImageSearchOptions) ([]registry.SearchResult, error)
	ImageSave(ctx context.Context, images []string) (io.ReadCloser, error)
	ImageTag(ctx context.Context, image, ref string) error
	ImagesPrune(ctx context.Context, pruneFilter filters.Args) (types.ImagesPruneReport, error)
}

ImageAPIClient defines API client methods for the images

type NetworkAPIClient

type NetworkAPIClient interface {
	NetworkConnect(ctx context.Context, network, container string, config *network.EndpointSettings) error
	NetworkCreate(ctx context.Context, name string, options types.NetworkCreate) (types.NetworkCreateResponse, error)
	NetworkDisconnect(ctx context.Context, network, container string, force bool) error
	NetworkInspect(ctx context.Context, network string, options types.NetworkInspectOptions) (types.NetworkResource, error)
	NetworkInspectWithRaw(ctx context.Context, network string, options types.NetworkInspectOptions) (types.NetworkResource, []byte, error)
	NetworkList(ctx context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error)
	NetworkRemove(ctx context.Context, network string) error
	NetworksPrune(ctx context.Context, pruneFilter filters.Args) (types.NetworksPruneReport, error)
}

NetworkAPIClient defines API client methods for the networks

type NodeAPIClient

type NodeAPIClient interface {
	NodeInspectWithRaw(ctx context.Context, nodeID string) (swarm.Node, []byte, error)
	NodeList(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error)
	NodeRemove(ctx context.Context, nodeID string, options types.NodeRemoveOptions) error
	NodeUpdate(ctx context.Context, nodeID string, version swarm.Version, node swarm.NodeSpec) error
}

NodeAPIClient defines API client methods for the nodes

type Opt

type Opt func(*Client) error

Opt is a configuration option to initialize a Client.

func WithAPIVersionNegotiation

func WithAPIVersionNegotiation() Opt

WithAPIVersionNegotiation enables automatic API version negotiation for the client. With this option enabled, the client automatically negotiates the API version to use when making requests. API version negotiation is performed on the first request; subsequent requests do not re-negotiate.

func WithDialContext

func WithDialContext(dialContext func(ctx context.Context, network, addr string) (net.Conn, error)) Opt

WithDialContext applies the dialer to the client transport. This can be used to set the Timeout and KeepAlive settings of the client. It returns an error if the client does not have a http.Transport configured.

func WithHTTPClient

func WithHTTPClient(client *http.Client) Opt

WithHTTPClient overrides the client's HTTP client with the specified one.

func WithHTTPHeaders

func WithHTTPHeaders(headers map[string]string) Opt

WithHTTPHeaders appends custom HTTP headers to the client's default headers. It does not allow for built-in headers (such as "User-Agent", if set) to be overridden. Also see WithUserAgent.

func WithHost

func WithHost(host string) Opt

WithHost overrides the client host with the specified one.

func WithHostFromEnv

func WithHostFromEnv() Opt

WithHostFromEnv overrides the client host with the host specified in the DOCKER_HOST (EnvOverrideHost) environment variable. If DOCKER_HOST is not set, or set to an empty value, the host is not modified.

func WithScheme

func WithScheme(scheme string) Opt

WithScheme overrides the client scheme with the specified one.

func WithTLSClientConfig

func WithTLSClientConfig(cacertPath, certPath, keyPath string) Opt

WithTLSClientConfig applies a TLS config to the client transport.

func WithTLSClientConfigFromEnv

func WithTLSClientConfigFromEnv() Opt

WithTLSClientConfigFromEnv configures the client's TLS settings with the settings in the DOCKER_CERT_PATH (EnvOverrideCertPath) and DOCKER_TLS_VERIFY (EnvTLSVerify) environment variables. If DOCKER_CERT_PATH is not set or empty, TLS configuration is not modified.

WithTLSClientConfigFromEnv uses the following environment variables:

  • DOCKER_CERT_PATH (EnvOverrideCertPath) to specify the directory from which to load the TLS certificates ("ca.pem", "cert.pem", "key.pem").
  • DOCKER_TLS_VERIFY (EnvTLSVerify) to enable or disable TLS verification (off by default).

func WithTimeout

func WithTimeout(timeout time.Duration) Opt

WithTimeout configures the time limit for requests made by the HTTP client.

func WithTraceProvider

func WithTraceProvider(provider trace.TracerProvider) Opt

WithTraceProvider sets the trace provider for the client. If this is not set then the global trace provider will be used.

func WithUserAgent

func WithUserAgent(ua string) Opt

WithUserAgent configures the User-Agent header to use for HTTP requests. It overrides any User-Agent set in headers. When set to an empty string, the User-Agent header is removed, and no header is sent.

func WithVersion

func WithVersion(version string) Opt

WithVersion overrides the client version with the specified one. If an empty version is provided, the value is ignored to allow version negotiation (see WithAPIVersionNegotiation).

func WithVersionFromEnv

func WithVersionFromEnv() Opt

WithVersionFromEnv overrides the client version with the version specified in the DOCKER_API_VERSION (EnvOverrideAPIVersion) environment variable. If DOCKER_API_VERSION is not set, or set to an empty value, the version is not modified.

type PluginAPIClient

type PluginAPIClient interface {
	PluginList(ctx context.Context, filter filters.Args) (types.PluginsListResponse, error)
	PluginRemove(ctx context.Context, name string, options types.PluginRemoveOptions) error
	PluginEnable(ctx context.Context, name string, options types.PluginEnableOptions) error
	PluginDisable(ctx context.Context, name string, options types.PluginDisableOptions) error
	PluginInstall(ctx context.Context, name string, options types.PluginInstallOptions) (io.ReadCloser, error)
	PluginUpgrade(ctx context.Context, name string, options types.PluginInstallOptions) (io.ReadCloser, error)
	PluginPush(ctx context.Context, name string, registryAuth string) (io.ReadCloser, error)
	PluginSet(ctx context.Context, name string, args []string) error
	PluginInspectWithRaw(ctx context.Context, name string) (*types.Plugin, []byte, error)
	PluginCreate(ctx context.Context, createContext io.Reader, options types.PluginCreateOptions) error
}

PluginAPIClient defines API client methods for the plugins

type SecretAPIClient

type SecretAPIClient interface {
	SecretList(ctx context.Context, options types.SecretListOptions) ([]swarm.Secret, error)
	SecretCreate(ctx context.Context, secret swarm.SecretSpec) (types.SecretCreateResponse, error)
	SecretRemove(ctx context.Context, id string) error
	SecretInspectWithRaw(ctx context.Context, name string) (swarm.Secret, []byte, error)
	SecretUpdate(ctx context.Context, id string, version swarm.Version, secret swarm.SecretSpec) error
}

SecretAPIClient defines API client methods for secrets

type ServiceAPIClient

type ServiceAPIClient interface {
	ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options types.ServiceCreateOptions) (swarm.ServiceCreateResponse, error)
	ServiceInspectWithRaw(ctx context.Context, serviceID string, options types.ServiceInspectOptions) (swarm.Service, []byte, error)
	ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error)
	ServiceRemove(ctx context.Context, serviceID string) error
	ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error)
	ServiceLogs(ctx context.Context, serviceID string, options container.LogsOptions) (io.ReadCloser, error)
	TaskLogs(ctx context.Context, taskID string, options container.LogsOptions) (io.ReadCloser, error)
	TaskInspectWithRaw(ctx context.Context, taskID string) (swarm.Task, []byte, error)
	TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error)
}

ServiceAPIClient defines API client methods for the services

type SwarmAPIClient

type SwarmAPIClient interface {
	SwarmInit(ctx context.Context, req swarm.InitRequest) (string, error)
	SwarmJoin(ctx context.Context, req swarm.JoinRequest) error
	SwarmGetUnlockKey(ctx context.Context) (types.SwarmUnlockKeyResponse, error)
	SwarmUnlock(ctx context.Context, req swarm.UnlockRequest) error
	SwarmLeave(ctx context.Context, force bool) error
	SwarmInspect(ctx context.Context) (swarm.Swarm, error)
	SwarmUpdate(ctx context.Context, version swarm.Version, swarm swarm.Spec, flags swarm.UpdateFlags) error
}

SwarmAPIClient defines API client methods for the swarm

type SystemAPIClient

type SystemAPIClient interface {
	Events(ctx context.Context, options types.EventsOptions) (<-chan events.Message, <-chan error)
	Info(ctx context.Context) (system.Info, error)
	RegistryLogin(ctx context.Context, auth registry.AuthConfig) (registry.AuthenticateOKBody, error)
	DiskUsage(ctx context.Context, options types.DiskUsageOptions) (types.DiskUsage, error)
	Ping(ctx context.Context) (types.Ping, error)
}

SystemAPIClient defines API client methods for the system

type VolumeAPIClient

type VolumeAPIClient interface {
	VolumeCreate(ctx context.Context, options volume.CreateOptions) (volume.Volume, error)
	VolumeInspect(ctx context.Context, volumeID string) (volume.Volume, error)
	VolumeInspectWithRaw(ctx context.Context, volumeID string) (volume.Volume, []byte, error)
	VolumeList(ctx context.Context, options volume.ListOptions) (volume.ListResponse, error)
	VolumeRemove(ctx context.Context, volumeID string, force bool) error
	VolumesPrune(ctx context.Context, pruneFilter filters.Args) (types.VolumesPruneReport, error)
	VolumeUpdate(ctx context.Context, volumeID string, version swarm.Version, options volume.UpdateOptions) error
}

VolumeAPIClient defines API client methods for the volumes

Source Files

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL