Documentation
¶
Index ¶
- func NewSSHClient(cfg *Config) (*ssh.Client, error)
- type Client
- func (cli *Client) AllShorts(ctx context.Context) ([]container.Short, error)
- func (cli *Client) Close() error
- func (cli *Client) CopyFrom(ctx context.Context, src file.Info, dst string) (string, error)
- func (cli *Client) DaemonHost() string
- func (cli *Client) DaemonVersion() string
- func (cli *Client) Details(ctx context.Context, id string) (container.Details, error)
- func (cli *Client) Engine(ctx context.Context) (engine.Info, error)
- func (cli *Client) FilesIn(ctx context.Context, root file.Info) ([]file.Info, error)
- func (cli *Client) Logs(ctx context.Context, id string) (LogSeq, context.CancelFunc)
- func (cli *Client) PauseContainer(ctx context.Context, id string) error
- func (cli *Client) ReadFile(ctx context.Context, f file.Info, limit int64) (data []byte, truncated bool, err error)
- func (cli *Client) RemoveContainer(ctx context.Context, id string) error
- func (cli *Client) RestartContainer(ctx context.Context, id string) error
- func (cli *Client) StartContainer(ctx context.Context, id string) error
- func (cli *Client) Stats(ctx context.Context, id string) StatsSeq
- func (cli *Client) StopContainer(ctx context.Context, id string) error
- func (cli *Client) Terminal(ctx context.Context, id string, in io.Reader, out io.Writer) error
- func (cli *Client) UnpauseContainer(ctx context.Context, id string) error
- type ClientOptions
- type Config
- type LogSeq
- type StatsSeq
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewSSHClient ¶
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:
- Password prompt, if cfg.AskPassword() is true.
- SSH agent via SSH_AUTH_SOCK, if the socket is available and has signers.
- 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) CopyFrom ¶
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 (*Client) DaemonVersion ¶
func (*Client) FilesIn ¶
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) PauseContainer ¶
func (*Client) ReadFile ¶ added in v1.1.0
func (cli *Client) ReadFile(ctx context.Context, f file.Info, limit int64) (data []byte, truncated bool, err error)
ReadFile returns up to limit bytes of the regular file f inside its container, following symbolic links. truncated reports whether the file is longer than limit.
func (*Client) RemoveContainer ¶
RemoveContainer removes a stopped container but keeps its volumes. The daemon refuses to remove a running container.
func (*Client) RestartContainer ¶
func (*Client) StartContainer ¶
func (*Client) Stats ¶
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 ¶
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.