Documentation
¶
Overview ¶
Package docker provides Docker Engine operations used by rolling deployments.
Each Client talks to a single Docker host (unix socket or TCP URL).
Index ¶
- func DefaultHost() string
- type Client
- func (c *Client) Close() error
- func (c *Client) Host() string
- func (c *Client) Inspect(ctx context.Context, containerName string) (*ContainerSpec, error)
- func (c *Client) ListRunningNames(ctx context.Context) ([]string, error)
- func (c *Client) Pull(ctx context.Context, imageName string) error
- func (c *Client) Remove(ctx context.Context, containerName string) error
- func (c *Client) Rename(ctx context.Context, oldContainerName, newContainerName string) error
- func (c *Client) Run(ctx context.Context, spec *ContainerSpec) (string, error)
- func (c *Client) Start(ctx context.Context, containerName string) error
- func (c *Client) Stop(ctx context.Context, containerName string) error
- type ContainerSpec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultHost ¶
func DefaultHost() string
DefaultHost returns the Docker host URL for the current environment.
Resolution order:
- DOCKER_HOST, if set
- the first existing Docker socket among well-known local paths (Docker Desktop on macOS/Linux home dirs, then /var/run/docker.sock)
- the OS default from the Moby client (unix:///var/run/docker.sock or the Windows named pipe)
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps a Docker Engine API client bound to one host.
func New ¶
New creates a Client for the given Docker host.
host is a Docker host URL such as:
- unix:///var/run/docker.sock
- tcp://192.168.1.10:2375
- ssh://user@host
func (*Client) Inspect ¶
Inspect returns the ContainerSpec that uniquely identifies how the named container was created (labels, volumes/mounts, networks, env, ports, etc.).
func (*Client) ListRunningNames ¶
ListRunningNames returns the names of containers currently running on this host, without Docker's leading slash.
func (*Client) Run ¶
Run creates and starts a container from spec (typically produced by Inspect, then adjusted via WithImage / WithName).
Spec from Inspect has no name and no endpoint IPs/MACs, so it will not collide with the inspected container on those. Free the desired name (and published ports) first — e.g. Rename + Stop — then WithName before Run. It returns the new container ID.
type ContainerSpec ¶
type ContainerSpec struct {
// Name is the container name without a leading slash.
// Empty after Inspect; set with WithName before Run when a name is desired.
Name string
Config *container.Config
HostConfig *container.HostConfig
NetworkingConfig *network.NetworkingConfig
}
ContainerSpec captures recreate parameters from docker inspect: labels, env, mounts/volumes, network membership, ports, restart policy, and related host/config settings.
Inspect deliberately omits instance identity that would conflict with the still-existing source container:
- Name is left empty (set explicitly via WithName after Rename frees it)
- Endpoint IPs / MAC addresses are not copied (Docker allocates new ones)
Callers are expected to free conflicting host resources (name, published ports) before Run — typically Rename + Stop the old container first.
func (*ContainerSpec) WithImage ¶
func (s *ContainerSpec) WithImage(image string) *ContainerSpec
WithImage returns a shallow copy of the spec with Config.Image set to image. The original spec is not modified.
func (*ContainerSpec) WithName ¶
func (s *ContainerSpec) WithName(name string) *ContainerSpec
WithName returns a shallow copy of the spec with Name set. Use only after the previous holder of that name has been renamed or removed.