client

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSSHClient

func NewSSHClient(cfg *Config) (*ssh.Client, error)

NewSSHClient creates a new SSH client from the given config.

Settings from ~/.ssh/config, and /etc/ssh/ssh_config if enabled, are applied first. They fill in the host name, port, username and identity file unless given on the command line. Host keys are verified against ~/.ssh/known_hosts.

Authentication is attempted in order:

  1. Password prompt, if cfg.AskPassword() is true.
  2. SSH agent via SSH_AUTH_SOCK, if the socket is available and has signers.
  3. Identity file (defaults: id_ed25519, id_rsa, id_ecdsa); prompts for passphrase if needed.

Types

type Client

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

func New

func New(cOpts ...ClientOptions) (*Client, error)

func (*Client) AllShorts

func (cli *Client) AllShorts(ctx context.Context) ([]container.Short, error)

func (*Client) Close

func (cli *Client) Close() error

func (*Client) CopyFrom

func (cli *Client) CopyFrom(ctx context.Context, src file.Info, dst string) (string, error)

CopyFrom copies the file or directory src out of its container to dst on the local machine, like docker cp: if dst is an existing directory or ends with a separator, src is copied into it under its own name. Directories are copied recursively. Nothing is overwritten; if the target already exists, CopyFrom fails. It returns the absolute path that was written.

func (*Client) DaemonHost

func (cli *Client) DaemonHost() string

func (*Client) DaemonVersion

func (cli *Client) DaemonVersion() string

func (*Client) Details

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

Details returns the inspect information of container id.

func (*Client) Engine

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

Engine returns the version and system information of the Docker host.

func (*Client) FilesIn

func (cli *Client) FilesIn(ctx context.Context, root file.Info) ([]file.Info, error)

FilesIn returns the files in the given directory inside the container. If the Path field of the root is empty, it defaults to the working directory of the container, or "/" if the working directory is not set.

func (*Client) Logs

func (cli *Client) Logs(ctx context.Context, id string) (LogSeq, context.CancelFunc)

func (*Client) PauseContainer

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

func (*Client) RemoveContainer

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

RemoveContainer removes a stopped container but keeps its volumes. The daemon refuses to remove a running container.

func (*Client) RestartContainer

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

func (*Client) StartContainer

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

func (*Client) Stats

func (cli *Client) Stats(ctx context.Context, id string) StatsSeq

Stats streams the resource usage of container id, about one sample per second, until ctx is canceled or the consumer stops. A container that isn't running yields empty samples.

func (*Client) StopContainer

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

func (*Client) Terminal

func (cli *Client) Terminal(ctx context.Context, id string, in io.Reader, out io.Writer) error

Terminal opens an interactive shell session inside the container identified by id. It creates a Docker exec process, attaches stdin/stdout/stderr with a PTY, and bridges in/out to the exec connection. The call blocks until the shell exits.

func (*Client) UnpauseContainer

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

type ClientOptions

type ClientOptions func(*Config)

func WithAskPassword

func WithAskPassword(ask bool) ClientOptions

func WithDockerHost

func WithDockerHost(host string) ClientOptions

func WithHost

func WithHost(host string) ClientOptions

func WithIdentityFile

func WithIdentityFile(identityFile string) ClientOptions

func WithSystemSSHConfig

func WithSystemSSHConfig(enable bool) ClientOptions

WithSystemSSHConfig enables reading /etc/ssh/ssh_config after ~/.ssh/config.

func WithUsername

func WithUsername(username string) ClientOptions

type Config

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

func NewConfig

func NewConfig(opts ...ClientOptions) (*Config, error)

NewSSHClient creates a new SSH client for the given optins.

Note that the host, username, port and identity file can be rewritten during ssh client construction with the value provided in the ~/.ssh/config file.

Use the method of the client to get the constructed Addr, Host, Port, Username, AskPassword, SSHDir and DockerSocket.

func (*Config) Addr

func (cfg *Config) Addr() string

func (*Config) AskPassword

func (cfg *Config) AskPassword() bool

func (*Config) DockerHost

func (cfg *Config) DockerHost() string

func (*Config) Host

func (cfg *Config) Host() string

func (*Config) Port

func (cfg *Config) Port() string

func (*Config) SSHDir

func (cfg *Config) SSHDir() string

func (*Config) Username

func (cfg *Config) Username() string

type LogSeq

type LogSeq = iter.Seq2[string, error]

type StatsSeq

type StatsSeq = iter.Seq2[container.Stats, error]

Jump to

Keyboard shortcuts

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