docker

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package docker 实现 Docker 管理模块:查看容器、启停、日志,以及检查镜像更新并按原配置重建容器。

直接调用 Docker Engine API(默认 /var/run/docker.sock),不依赖官方 SDK。

Index

Constants

View Source
const ID = "docker"

ID 是模块标识。

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Status  int
	Message string
}

APIError 是 Docker 返回的错误。

func (*APIError) Error

func (e *APIError) Error() string

type Client

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

Client 是精简的 Docker Engine API 客户端。

func NewClient

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

NewClient 按地址创建客户端:unix:///var/run/docker.sock 或 tcp://host:2375。

func (*Client) Action

func (c *Client) Action(ctx context.Context, id, action string) error

Action 执行 start/stop/restart。

func (*Client) ConnectNetwork

func (c *Client) ConnectNetwork(ctx context.Context, network, id string, endpoint map[string]any) error

ConnectNetwork 把容器连接到网络。

func (*Client) Containers

func (c *Client) Containers(ctx context.Context) ([]Container, error)

Containers 列出全部容器。

func (*Client) Create

func (c *Client) Create(ctx context.Context, name string, body any) (string, error)

Create 创建容器,返回新容器 ID。

func (*Client) ImageID

func (c *Client) ImageID(ctx context.Context, ref string) (string, error)

ImageID 返回本地镜像 ID;镜像不存在时返回空字符串。

func (*Client) Inspect

func (c *Client) Inspect(ctx context.Context, id string) (map[string]json.RawMessage, error)

Inspect 返回容器详情的原始 JSON,重建容器时需要完整保留未知字段。

func (*Client) Logs

func (c *Client) Logs(ctx context.Context, id string, tail int) (string, error)

Logs 返回容器最近的日志。非 TTY 容器的输出是带 8 字节头的多路复用流,这里解析为纯文本。

func (*Client) Ping

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

Ping 检查 Docker 是否可用。

func (*Client) Pull

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

Pull 拉取镜像。返回的进度流逐行解析,遇到错误消息时返回错误。

func (*Client) Remove

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

Remove 删除容器(保留数据卷)。

func (*Client) Rename

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

Rename 重命名容器。

type Container

type Container struct {
	ID      string            `json:"Id"`
	Names   []string          `json:"Names"`
	Image   string            `json:"Image"`
	ImageID string            `json:"ImageID"`
	State   string            `json:"State"`
	Status  string            `json:"Status"`
	Created int64             `json:"Created"`
	Labels  map[string]string `json:"Labels"`
	Ports   []struct {
		IP          string `json:"IP"`
		PrivatePort int    `json:"PrivatePort"`
		PublicPort  int    `json:"PublicPort"`
		Type        string `json:"Type"`
	} `json:"Ports"`
}

Container 是容器列表项。

func (Container) Name

func (c Container) Name() string

Name 返回不带斜杠的容器名。

type ContainerView

type ContainerView struct {
	ID      string            `json:"id"`
	Name    string            `json:"name"`
	Image   string            `json:"image"`
	State   string            `json:"state"`
	Status  string            `json:"status"`
	Created int64             `json:"created"`
	Ports   []string          `json:"ports"`
	Project string            `json:"project,omitempty"`
	Update  *UpdateInfo       `json:"update,omitempty"`
	Busy    bool              `json:"busy"`
	Labels  map[string]string `json:"-"`
}

ContainerView 是界面展示的容器信息。

type Module

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

Module 是 Docker 管理模块。

func New

func New() *Module

New 创建模块。

func (*Module) ID

func (m *Module) ID() string

ID 实现 module.Module。

func (*Module) Init

func (m *Module) Init(env module.Env) error

Init 实现 module.Module。

func (*Module) Routes

func (m *Module) Routes(r module.Router)

Routes 实现 module.Module。

func (*Module) Start

func (m *Module) Start(context.Context) error

Start 实现 module.Module。

func (*Module) Stop

func (m *Module) Stop() error

Stop 实现 module.Module。

func (*Module) Title

func (m *Module) Title() string

Title 实现 module.Module。

type Settings

type Settings struct {
	// Host 为 Docker 地址,默认 unix:///var/run/docker.sock
	Host string `json:"host"`
}

Settings 是模块配置。

type UpdateInfo

type UpdateInfo struct {
	Checked   time.Time `json:"checked"`
	HasUpdate bool      `json:"hasUpdate"`
	Error     string    `json:"error,omitempty"`
}

UpdateInfo 是镜像更新检查结果。

Jump to

Keyboard shortcuts

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