docker

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: MIT Imports: 11 Imported by: 0

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

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:

  1. DOCKER_HOST, if set
  2. the first existing Docker socket among well-known local paths (Docker Desktop on macOS/Linux home dirs, then /var/run/docker.sock)
  3. 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

func New(host string) (*Client, error)

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) Close

func (c *Client) Close() error

Close releases resources held by the underlying Docker client.

func (*Client) Host

func (c *Client) Host() string

Host returns the Docker host URL this client is bound to.

func (*Client) Inspect

func (c *Client) Inspect(ctx context.Context, containerName string) (*ContainerSpec, error)

Inspect returns the ContainerSpec that uniquely identifies how the named container was created (labels, volumes/mounts, networks, env, ports, etc.).

func (*Client) ListRunningNames

func (c *Client) ListRunningNames(ctx context.Context) ([]string, error)

ListRunningNames returns the names of containers currently running on this host, without Docker's leading slash.

func (*Client) Pull

func (c *Client) Pull(ctx context.Context, imageName string) error

Pull pulls imageName from the registry configured for this Docker host.

func (*Client) Remove

func (c *Client) Remove(ctx context.Context, containerName string) error

Remove removes the named container.

func (*Client) Rename

func (c *Client) Rename(ctx context.Context, oldContainerName, newContainerName string) error

Rename renames a container from oldContainerName to newContainerName.

func (*Client) Run

func (c *Client) Run(ctx context.Context, spec *ContainerSpec) (string, error)

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.

func (*Client) Start

func (c *Client) Start(ctx context.Context, containerName string) error

Start starts an existing stopped container.

func (*Client) Stop

func (c *Client) Stop(ctx context.Context, containerName string) error

Stop stops the named container.

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.

Jump to

Keyboard shortcuts

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