dockerx

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client 是对 Docker SDK 的窄封装:只暴露本工具需要的能力。

func New

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

func (*Client) ContainerID

func (c *Client) ContainerID(ctx context.Context, name string) (string, error)

ContainerID 按名称/ID 取容器完整 ID(不要求运行中)。

func (*Client) Events

func (c *Client) Events(ctx context.Context) (<-chan events.Message, <-chan error)

Events 返回容器/网络相关事件流。

func (*Client) Host

func (c *Client) Host() string

Host 返回当前连接的 docker daemon 地址(用于状态展示)。

func (*Client) ListContainers

func (c *Client) ListContainers(ctx context.Context) ([]ContainerInfo, error)

ListContainers 返回运行中的容器。

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping 检测 daemon 连通性。

func (*Client) ResolveIP

func (c *Client) ResolveIP(ctx context.Context, name, network string) (ip, networkUsed, containerID string, err error)

ResolveIP 把容器名解析为当前 IP。 network 为空时取"网络名排序第一且有 IP"的网络;返回实际使用的网络名。

type ContainerInfo

type ContainerInfo struct {
	ID     string            `json:"id"`
	Name   string            `json:"name"`
	Image  string            `json:"image"`
	State  string            `json:"state"`
	Status string            `json:"status"`
	IPs    map[string]string `json:"ips,omitempty"` // network -> IP
	Ports  []string          `json:"ports,omitempty"`
}

ContainerInfo 是容器列表条目(供 WebUI 选择器使用)。

type Resolver

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

Resolver 维护"关注集"(被启用规则引用的容器名)的订阅关系, 订阅 Docker 事件流;任何相关事件触发去抖后的全量刷新回调。

func NewResolver

func NewResolver(cli *Client, pollInterval time.Duration) *Resolver

NewResolver pollInterval <= 0 时关闭兜底轮询。

func (*Resolver) LastSyncAt

func (r *Resolver) LastSyncAt() time.Time

LastSyncAt 返回最近一次全量刷新时间(可能为零值)。

func (*Resolver) ResolveIP

func (r *Resolver) ResolveIP(ctx context.Context, name, network string) (ip, networkUsed, containerID string, err error)

ResolveIP 把容器名解析为当前 IP(委托给 Client)。

func (*Resolver) Run

func (r *Resolver) Run(ctx context.Context)

Run 事件流主循环:断连后指数退避重连,重连成功先全量刷新补齐丢失事件。

func (*Resolver) State

func (r *Resolver) State() string

State 返回事件流状态:starting | connected | reconnecting。

func (*Resolver) Watch

func (r *Resolver) Watch(name string, cb func()) (unwatch func())

Watch 订阅容器变化;返回的函数用于退订。回调在事件去抖后触发。

Jump to

Keyboard shortcuts

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