// Package docker manages the host Docker daemon through its CLI. package docker import ( "errors" "fmt" ) var ( // ErrUnsupported means the panel host cannot run Docker commands. ErrUnsupported = errors.New("当前系统不支持 Docker 管理") // ErrNotInstalled means the docker binary is missing. ErrNotInstalled = errors.New("Docker 尚未安装,请先在应用商店安装 Docker") // ErrDaemonDown means the CLI exists but the daemon is not reachable. ErrDaemonDown = errors.New("Docker 已安装但守护进程未运行,请先启动 Docker 服务") // ErrInvalid marks a rejected parameter. ErrInvalid = errors.New("参数不合法") ) // Status is the Docker availability payload. type Status struct { Supported bool `json:"supported"` Installed bool `json:"installed"` Running bool `json:"running"` Version string `json:"version"` ComposeVersion string `json:"compose_version"` Mirrors []string `json:"mirrors"` PanelPort int `json:"panel_port"` NginxReady bool `json:"nginx_ready"` Message string `json:"message"` } // ResourceStat is one overview counter. type ResourceStat struct { Total int `json:"total"` Running int `json:"running,omitempty"` Size string `json:"size"` } // Overview is the dashboard payload. type Overview struct { Containers ResourceStat `json:"containers"` Images ResourceStat `json:"images"` Networks ResourceStat `json:"networks"` Volumes ResourceStat `json:"volumes"` Bindings int `json:"bindings"` } // Port is one container port mapping. type Port struct { HostIP string `json:"host_ip"` HostPort int `json:"host_port"` ContainerPort int `json:"container_port"` Protocol string `json:"protocol"` Published bool `json:"published"` } // Binding is one nginx proxy site bound to a container port. type Binding struct { SiteID int64 `json:"site_id"` Slug string `json:"slug"` Domains []string `json:"domains"` HostPort int `json:"host_port"` ContainerPort int `json:"container_port"` } // Container is one Docker container with its panel domain bindings. type Container struct { ID string `json:"id"` ShortID string `json:"short_id"` Name string `json:"name"` Image string `json:"image"` State string `json:"state"` Status string `json:"status"` CreatedAt string `json:"created_at"` Ports []Port `json:"ports"` Bindings []Binding `json:"bindings"` DomainNames []string `json:"domains"` } // Image is one local image. type Image struct { ID string `json:"id"` Repository string `json:"repository"` Tag string `json:"tag"` Size string `json:"size"` CreatedAt string `json:"created_at"` } // Network is one Docker network. type Network struct { ID string `json:"id"` Name string `json:"name"` Driver string `json:"driver"` Scope string `json:"scope"` } // Volume is one Docker volume. type Volume struct { Name string `json:"name"` Driver string `json:"driver"` Mountpoint string `json:"mountpoint"` Scope string `json:"scope"` } // BindingError carries the blocked bindings so the API can return them. type BindingError struct { Bindings []Binding } func (e *BindingError) Error() string { return fmt.Sprintf("容器还绑定了 %d 个域名,请先解绑或勾选同时删除站点", len(e.Bindings)) } // CreateResult is the outcome of a pasted run/compose command. type CreateResult struct { Mode string `json:"mode"` Stack string `json:"stack,omitempty"` Path string `json:"path,omitempty"` Output string `json:"output"` }