miaopanel
1// Package docker manages the host Docker daemon through its CLI.
2package docker
3
4import (
5 "errors"
6 "fmt"
7)
8
9var (
10 // ErrUnsupported means the panel host cannot run Docker commands.
11 ErrUnsupported = errors.New("当前系统不支持 Docker 管理")
12 // ErrNotInstalled means the docker binary is missing.
13 ErrNotInstalled = errors.New("Docker 尚未安装,请先在应用商店安装 Docker")
14 // ErrDaemonDown means the CLI exists but the daemon is not reachable.
15 ErrDaemonDown = errors.New("Docker 已安装但守护进程未运行,请先启动 Docker 服务")
16 // ErrInvalid marks a rejected parameter.
17 ErrInvalid = errors.New("参数不合法")
18)
19
20// Status is the Docker availability payload.
21type Status struct {
22 Supported bool `json:"supported"`
23 Installed bool `json:"installed"`
24 Running bool `json:"running"`
25 Version string `json:"version"`
26 ComposeVersion string `json:"compose_version"`
27 Mirrors []string `json:"mirrors"`
28 PanelPort int `json:"panel_port"`
29 NginxReady bool `json:"nginx_ready"`
30 Message string `json:"message"`
31}
32
33// ResourceStat is one overview counter.
34type ResourceStat struct {
35 Total int `json:"total"`
36 Running int `json:"running,omitempty"`
37 Size string `json:"size"`
38}
39
40// Overview is the dashboard payload.
41type Overview struct {
42 Containers ResourceStat `json:"containers"`
43 Images ResourceStat `json:"images"`
44 Networks ResourceStat `json:"networks"`
45 Volumes ResourceStat `json:"volumes"`
46 Bindings int `json:"bindings"`
47}
48
49// Port is one container port mapping.
50type Port struct {
51 HostIP string `json:"host_ip"`
52 HostPort int `json:"host_port"`
53 ContainerPort int `json:"container_port"`
54 Protocol string `json:"protocol"`
55 Published bool `json:"published"`
56}
57
58// Binding is one nginx proxy site bound to a container port.
59type Binding struct {
60 SiteID int64 `json:"site_id"`
61 Slug string `json:"slug"`
62 Domains []string `json:"domains"`
63 HostPort int `json:"host_port"`
64 ContainerPort int `json:"container_port"`
65}
66
67// Container is one Docker container with its panel domain bindings.
68type Container struct {
69 ID string `json:"id"`
70 ShortID string `json:"short_id"`
71 Name string `json:"name"`
72 Image string `json:"image"`
73 State string `json:"state"`
74 Status string `json:"status"`
75 CreatedAt string `json:"created_at"`
76 Ports []Port `json:"ports"`
77 Bindings []Binding `json:"bindings"`
78 DomainNames []string `json:"domains"`
79}
80
81// Image is one local image.
82type Image struct {
83 ID string `json:"id"`
84 Repository string `json:"repository"`
85 Tag string `json:"tag"`
86 Size string `json:"size"`
87 CreatedAt string `json:"created_at"`
88}
89
90// Network is one Docker network.
91type Network struct {
92 ID string `json:"id"`
93 Name string `json:"name"`
94 Driver string `json:"driver"`
95 Scope string `json:"scope"`
96}
97
98// Volume is one Docker volume.
99type Volume struct {
100 Name string `json:"name"`
101 Driver string `json:"driver"`
102 Mountpoint string `json:"mountpoint"`
103 Scope string `json:"scope"`
104}
105
106// BindingError carries the blocked bindings so the API can return them.
107type BindingError struct {
108 Bindings []Binding
109}
110
111func (e *BindingError) Error() string {
112 return fmt.Sprintf("容器还绑定了 %d 个域名,请先解绑或勾选同时删除站点", len(e.Bindings))
113}
114
115// CreateResult is the outcome of a pasted run/compose command.
116type CreateResult struct {
117 Mode string `json:"mode"`
118 Stack string `json:"stack,omitempty"`
119 Path string `json:"path,omitempty"`
120 Output string `json:"output"`
121}