docker

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Overview

Package docker 应用商店目录服务 加载 docker-apps.yaml,提供应用浏览、搜索、分类查询

Package docker HTTP 处理器

Package docker 已安装应用服务 管理 Docker 应用的安装、卸载、启停、日志等生命周期操作

Package docker 已安装应用 HTTP 处理器

Package docker 提供 Docker 容器管理和应用商店模块

Package docker 端口检测服务

Package docker Docker 服务

Package docker 应用商店 HTTP 处理器

Package docker Docker 类型定义

Index

Constants

View Source
const (
	ModuleID      = "docker"
	ModuleName    = "Docker App Store"
	ModuleVersion = "1.0.0"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AppRaw

type AppRaw struct {
	ID            string            `yaml:"id"`
	Name          string            `yaml:"name"`
	Platform      string            `yaml:"platform"`
	Category      string            `yaml:"category"`
	Author        string            `yaml:"author,omitempty"`
	License       string            `yaml:"license,omitempty"`
	Homepage      string            `yaml:"homepage"`
	Repository    string            `yaml:"repository"`
	Icon          string            `yaml:"icon"`
	Version       string            `yaml:"version"`
	Architectures []string          `yaml:"architectures"`
	Tags          []string          `yaml:"tags"`
	Title         map[string]string `yaml:"title"`
	Description   map[string]string `yaml:"description"`
	Form          []FormFieldRaw    `yaml:"form"`
	Compose       yaml.Node         `yaml:"compose"` // 保持原始 YAML 结构
}

AppRaw 单个应用的 YAML 原始结构

type AppStoreRaw

type AppStoreRaw struct {
	Apps    []AppRaw `yaml:"apps"`
	Version string   `yaml:"version"`
}

AppStoreRaw YAML 顶层结构

type CatalogService

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

CatalogService 应用目录服务

func NewCatalogService

func NewCatalogService(yamlPath string, logger *zap.Logger) (*CatalogService, error)

NewCatalogService 创建目录服务

func (*CatalogService) AppCount

func (cs *CatalogService) AppCount() int

AppCount 获取应用数量

func (*CatalogService) GetApp

func (cs *CatalogService) GetApp(id string) *StoreApp

GetApp 获取单个应用详情

func (*CatalogService) GetApps

func (cs *CatalogService) GetApps(category, search string) []StoreApp

GetApps 获取应用列表(支持分类和搜索筛选)

func (*CatalogService) GetCategories

func (cs *CatalogService) GetCategories() []StoreCategory

GetCategories 获取分类列表

type ContainerConfig

type ContainerConfig struct {
	Name        string            `json:"name"`
	Image       string            `json:"image"`
	Ports       map[string]string `json:"ports"`
	Volumes     map[string]string `json:"volumes"`
	Environment []string          `json:"environment"`
	Networks    []string          `json:"networks"`
	Labels      map[string]string `json:"labels"`
	Restart     string            `json:"restart"`
	Privileged  bool              `json:"privileged"`
	CapAdd      []string          `json:"cap_add"`
	Devices     []string          `json:"devices"`
	Command     []string          `json:"command"`
}

ContainerConfig 容器创建配置

type ContainerInfo

type ContainerInfo struct {
	ID      string        `json:"id"`
	Name    string        `json:"name"`
	Image   string        `json:"image"`
	ImageID string        `json:"image_id"`
	State   string        `json:"state"`
	Status  string        `json:"status"`
	Created int64         `json:"created"`
	Ports   []PortBinding `json:"ports"`
}

ContainerInfo 容器简要信息

type ContainerStats

type ContainerStats struct {
	CPUPercent    float64 `json:"cpu_percent"`
	MemoryUsage   uint64  `json:"memory_usage"`
	MemoryLimit   uint64  `json:"memory_limit"`
	MemoryPercent float64 `json:"memory_percent"`
	NetworkRx     uint64  `json:"network_rx"`
	NetworkTx     uint64  `json:"network_tx"`
	BlockRead     uint64  `json:"block_read"`
	BlockWrite    uint64  `json:"block_write"`
}

ContainerStats 容器资源统计

type ContainerStatus

type ContainerStatus struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	Image     string `json:"image"`
	State     string `json:"state"`
	Running   bool   `json:"running"`
	StartedAt string `json:"started_at"`
	ExitCode  int    `json:"exit_code"`
}

ContainerStatus 容器状态

type CreateContainerRequest

type CreateContainerRequest struct {
	Name        string            `json:"name" binding:"required"`
	Image       string            `json:"image" binding:"required"`
	Ports       map[string]string `json:"ports"`
	Volumes     map[string]string `json:"volumes"`
	Environment []string          `json:"environment"`
	Networks    []string          `json:"networks"`
	Labels      map[string]string `json:"labels"`
	Restart     string            `json:"restart"`
	Privileged  bool              `json:"privileged"`
	CapAdd      []string          `json:"cap_add"`
	Devices     []string          `json:"devices"`
	Command     []string          `json:"command"`
}

CreateContainerRequest 创建容器请求

type CreateNetworkRequest

type CreateNetworkRequest struct {
	Name   string `json:"name" binding:"required"`
	Driver string `json:"driver"`
}

CreateNetworkRequest 创建网络请求

type DockerInfo

type DockerInfo struct {
	Version           string `json:"version"`
	APIVersion        string `json:"api_version"`
	OS                string `json:"os"`
	Arch              string `json:"arch"`
	KernelVersion     string `json:"kernel_version"`
	Containers        int    `json:"containers"`
	ContainersRunning int    `json:"containers_running"`
	ContainersStopped int    `json:"containers_stopped"`
	Images            int    `json:"images"`
	Driver            string `json:"driver"`
	MemTotal          int64  `json:"mem_total"`
	NCPU              int    `json:"ncpu"`
}

DockerInfo Docker 系统信息

type FormField

type FormField struct {
	Key      string      `json:"key"`
	Label    LocaleText  `json:"label"`
	Default  interface{} `json:"default,omitempty"`
	Required bool        `json:"required"`
	Type     string      `json:"type"`
	EnvKey   string      `json:"env_key,omitempty"`
}

FormField 表单字段(API 响应)

type FormFieldRaw

type FormFieldRaw struct {
	Key      string            `yaml:"key"`
	Label    map[string]string `yaml:"label"`
	Default  interface{}       `yaml:"default,omitempty"`
	Required bool              `yaml:"required,omitempty"`
	Type     string            `yaml:"type"`
	EnvKey   string            `yaml:"env_key,omitempty"`
}

FormFieldRaw 表单字段原始结构

type Handler

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

Handler HTTP 处理器

func NewHandler

func NewHandler(service *Service, logger *zap.Logger) *Handler

NewHandler 创建处理器

func (*Handler) CreateContainer

func (h *Handler) CreateContainer(c *gin.Context)

CreateContainer 创建容器

func (*Handler) CreateNetwork

func (h *Handler) CreateNetwork(c *gin.Context)

CreateNetwork 创建网络

func (*Handler) ExecContainer

func (h *Handler) ExecContainer(c *gin.Context)

ExecContainer 在容器内执行命令

func (*Handler) GetContainerLogs

func (h *Handler) GetContainerLogs(c *gin.Context)

GetContainerLogs 获取容器日志

func (*Handler) GetContainerStats

func (h *Handler) GetContainerStats(c *gin.Context)

GetContainerStats 获取容器统计

func (*Handler) GetContainerStatus

func (h *Handler) GetContainerStatus(c *gin.Context)

GetContainerStatus 获取容器状态

func (*Handler) GetInfo

func (h *Handler) GetInfo(c *gin.Context)

GetInfo 获取 Docker 信息

func (*Handler) GetStatus

func (h *Handler) GetStatus(c *gin.Context)

GetStatus 获取 Docker 运行状态

func (*Handler) ListContainers

func (h *Handler) ListContainers(c *gin.Context)

ListContainers 列出容器

func (*Handler) ListImages

func (h *Handler) ListImages(c *gin.Context)

ListImages 列出镜像

func (*Handler) ListNetworks

func (h *Handler) ListNetworks(c *gin.Context)

ListNetworks 列出网络

func (*Handler) PullImage

func (h *Handler) PullImage(c *gin.Context)

PullImage 拉取镜像

func (*Handler) RegisterRoutes

func (h *Handler) RegisterRoutes(r *gin.RouterGroup)

RegisterRoutes 注册路由

func (*Handler) RemoveContainer

func (h *Handler) RemoveContainer(c *gin.Context)

RemoveContainer 删除容器

func (*Handler) RemoveImage

func (h *Handler) RemoveImage(c *gin.Context)

RemoveImage 删除镜像

func (*Handler) RemoveNetwork

func (h *Handler) RemoveNetwork(c *gin.Context)

RemoveNetwork 删除网络

func (*Handler) RestartContainer

func (h *Handler) RestartContainer(c *gin.Context)

RestartContainer 重启容器

func (*Handler) StartContainer

func (h *Handler) StartContainer(c *gin.Context)

StartContainer 启动容器

func (*Handler) StopContainer

func (h *Handler) StopContainer(c *gin.Context)

StopContainer 停止容器

type ImageInfo

type ImageInfo struct {
	ID         string `json:"id"`
	Repository string `json:"repository"`
	Tag        string `json:"tag"`
	Size       int64  `json:"size"`
	Created    int64  `json:"created"`
}

ImageInfo 镜像信息

type InstallTask

type InstallTask struct {
	ID        string    `json:"id"`
	AppID     string    `json:"app_id"`
	Name      string    `json:"name"`
	Status    string    `json:"status"` // "pending", "running", "success", "failed"
	Output    string    `json:"output"`
	Error     string    `json:"error,omitempty"`
	CreatedAt time.Time `json:"created_at"`
	DoneAt    time.Time `json:"done_at,omitempty"`
}

InstallTask 安装任务(异步)

type InstalledApp

type InstalledApp struct {
	Name        string                 `json:"name"`
	AppID       string                 `json:"app_id"`
	Version     string                 `json:"version"`
	Icon        string                 `json:"icon"`
	Status      string                 `json:"status"`
	Config      map[string]interface{} `json:"config"`
	ComposePath string                 `json:"compose_path"`
	InstalledAt time.Time              `json:"installed_at"`
}

InstalledApp 已安装应用

type InstalledHandler

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

InstalledHandler 已安装应用 HTTP 处理器

func NewInstalledHandler

func NewInstalledHandler(installed *InstalledService, logger *zap.Logger) *InstalledHandler

NewInstalledHandler 创建处理器

func (*InstalledHandler) GetLogs

func (h *InstalledHandler) GetLogs(c *gin.Context)

GetLogs 获取应用日志 GET /docker/apps/:name/logs?tail=100

func (*InstalledHandler) GetTask

func (h *InstalledHandler) GetTask(c *gin.Context)

GetTask 获取安装任务状态 GET /docker/apps/tasks/:taskId

func (*InstalledHandler) Install

func (h *InstalledHandler) Install(c *gin.Context)

Install 安装应用 POST /docker/apps { app_id, config }

func (*InstalledHandler) InstallAsync

func (h *InstalledHandler) InstallAsync(c *gin.Context)

InstallAsync 异步安装应用 POST /docker/apps/async { app_id, config }

func (*InstalledHandler) List

func (h *InstalledHandler) List(c *gin.Context)

List 获取已安装应用列表 GET /docker/apps

func (*InstalledHandler) RegisterRoutes

func (h *InstalledHandler) RegisterRoutes(r *gin.RouterGroup)

RegisterRoutes 注册路由

func (*InstalledHandler) Restart

func (h *InstalledHandler) Restart(c *gin.Context)

Restart 重启应用 POST /docker/apps/:name/restart

func (*InstalledHandler) Start

func (h *InstalledHandler) Start(c *gin.Context)

Start 启动应用 POST /docker/apps/:name/start

func (*InstalledHandler) Stop

func (h *InstalledHandler) Stop(c *gin.Context)

Stop 停止应用 POST /docker/apps/:name/stop

func (*InstalledHandler) Uninstall

func (h *InstalledHandler) Uninstall(c *gin.Context)

Uninstall 卸载应用 DELETE /docker/apps/:name

type InstalledService

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

InstalledService 已安装应用服务

func NewInstalledService

func NewInstalledService(dataDir string, catalog *CatalogService, logger *zap.Logger) (*InstalledService, error)

NewInstalledService 创建已安装应用服务

func (*InstalledService) Get

func (is *InstalledService) Get(name string) *InstalledApp

Get 获取单个已安装应用

func (*InstalledService) GetAll

func (is *InstalledService) GetAll() []*InstalledApp

GetAll 获取所有已安装应用(含实时状态)

func (*InstalledService) GetLogs

func (is *InstalledService) GetLogs(name string, tail int) (string, error)

GetLogs 获取应用日志

func (*InstalledService) GetTask

func (is *InstalledService) GetTask(taskID string) *InstallTask

GetTask 获取安装任务状态

func (*InstalledService) Install

func (is *InstalledService) Install(appID string, config map[string]interface{}) (*InstalledApp, string, error)

Install 安装应用(同步)

func (*InstalledService) InstallAsync

func (is *InstalledService) InstallAsync(appID string, config map[string]interface{}) (*InstallTask, error)

InstallAsync 异步安装应用,返回任务 ID

func (*InstalledService) InstallStreaming

func (is *InstalledService) InstallStreaming(appID string, config map[string]interface{}, onOutput func(string)) (*InstalledApp, string, error)

InstallStreaming 安装应用(流式输出版本) onOutput 回调在每读到新行时被调用,用于实时更新进度

func (*InstalledService) Restart

func (is *InstalledService) Restart(name string) error

Restart 重启应用

func (*InstalledService) Start

func (is *InstalledService) Start(name string) error

Start 启动应用

func (*InstalledService) Stop

func (is *InstalledService) Stop(name string) error

Stop 停止应用

func (*InstalledService) Uninstall

func (is *InstalledService) Uninstall(name string) error

Uninstall 卸载应用

type LocaleText

type LocaleText struct {
	En string `json:"en"`
	Zh string `json:"zh"`
}

LocaleText 多语言文本

type Module

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

Module Docker应用模块

func New

func New() *Module

New 创建模块实例

func (*Module) Dependencies

func (m *Module) Dependencies() []string

Dependencies 返回依赖模块

func (*Module) GetCatalog

func (m *Module) GetCatalog() *CatalogService

GetCatalog 获取目录服务实例(供其他模块调用)

func (*Module) GetService

func (m *Module) GetService() *Service

GetService 获取服务实例(供其他模块调用)

func (*Module) ID

func (m *Module) ID() string

ID 返回模块ID

func (*Module) Init

func (m *Module) Init(ctx *module.Context) error

Init 初始化模块

func (*Module) Name

func (m *Module) Name() string

Name 返回模块名称

func (*Module) RegisterRoutes

func (m *Module) RegisterRoutes(group *gin.RouterGroup)

RegisterRoutes 注册路由

func (*Module) Start

func (m *Module) Start() error

Start 启动模块

func (*Module) Stop

func (m *Module) Stop() error

Stop 停止模块

func (*Module) Version

func (m *Module) Version() string

Version 返回模块版本

type NetworkInfo

type NetworkInfo struct {
	ID      string `json:"id"`
	Name    string `json:"name"`
	Driver  string `json:"driver"`
	Scope   string `json:"scope"`
	Subnet  string `json:"subnet"`
	Gateway string `json:"gateway"`
}

NetworkInfo 网络信息

type PortBinding

type PortBinding struct {
	HostPort      string `json:"host_port"`
	ContainerPort string `json:"container_port"`
	Protocol      string `json:"protocol"`
}

PortBinding 端口绑定

type PortHandler

type PortHandler struct{}

PortHandler 端口检测 HTTP 处理器

func NewPortHandler

func NewPortHandler() *PortHandler

NewPortHandler 创建端口处理器

func (*PortHandler) CheckPort

func (h *PortHandler) CheckPort(c *gin.Context)

CheckPort 检查端口是否可用 GET /docker/ports/check?port=8080

func (*PortHandler) RegisterRoutes

func (h *PortHandler) RegisterRoutes(r *gin.RouterGroup)

RegisterRoutes 注册路由

func (*PortHandler) SuggestPort

func (h *PortHandler) SuggestPort(c *gin.Context)

SuggestPort 建议可用端口 GET /docker/ports/suggest?preferred=8080

type PullImageRequest

type PullImageRequest struct {
	Image string `json:"image" binding:"required"`
}

PullImageRequest 拉取镜像请求

type Service

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

Service Docker 服务

func NewService

func NewService(logger *zap.Logger) (*Service, error)

NewService 创建服务

func (*Service) Close

func (s *Service) Close() error

Close 关闭服务

func (*Service) CreateContainer

func (s *Service) CreateContainer(ctx context.Context, config *ContainerConfig) (string, error)

CreateContainer 创建容器

func (*Service) CreateNetwork

func (s *Service) CreateNetwork(ctx context.Context, name, driver string) (string, error)

CreateNetwork 创建网络

func (*Service) ExecInContainer

func (s *Service) ExecInContainer(ctx context.Context, containerID string, command string) (string, error)

ExecInContainer 在容器内执行命令

func (*Service) GetContainerLogs

func (s *Service) GetContainerLogs(ctx context.Context, containerID string, tail int) (string, error)

GetContainerLogs 获取容器日志

func (*Service) GetContainerStats

func (s *Service) GetContainerStats(ctx context.Context, containerID string) (*ContainerStats, error)

GetContainerStats 获取容器统计

func (*Service) GetContainerStatus

func (s *Service) GetContainerStatus(ctx context.Context, containerID string) (*ContainerStatus, error)

GetContainerStatus 获取容器状态

func (*Service) GetInfo

func (s *Service) GetInfo(ctx context.Context) (*DockerInfo, error)

GetInfo 获取 Docker 信息

func (*Service) ImageExists

func (s *Service) ImageExists(ctx context.Context, image string) bool

ImageExists 检查镜像是否存在

func (*Service) IsRunning

func (s *Service) IsRunning(ctx context.Context) bool

IsRunning 检查 Docker 是否运行

func (*Service) ListContainers

func (s *Service) ListContainers(ctx context.Context, all bool) ([]ContainerInfo, error)

ListContainers 列出容器

func (*Service) ListImages

func (s *Service) ListImages(ctx context.Context) ([]ImageInfo, error)

ListImages 列出镜像

func (*Service) ListNetworks

func (s *Service) ListNetworks(ctx context.Context) ([]NetworkInfo, error)

ListNetworks 列出网络

func (*Service) PullImage

func (s *Service) PullImage(ctx context.Context, image string, progress chan<- string) error

PullImage 拉取镜像

func (*Service) RemoveContainer

func (s *Service) RemoveContainer(ctx context.Context, containerID string, force bool) error

RemoveContainer 删除容器

func (*Service) RemoveImage

func (s *Service) RemoveImage(ctx context.Context, imageID string) error

RemoveImage 删除镜像

func (*Service) RemoveNetwork

func (s *Service) RemoveNetwork(ctx context.Context, networkID string) error

RemoveNetwork 删除网络

func (*Service) RestartContainer

func (s *Service) RestartContainer(ctx context.Context, containerID string) error

RestartContainer 重启容器

func (*Service) StartContainer

func (s *Service) StartContainer(ctx context.Context, containerID string) error

StartContainer 启动容器

func (*Service) StopContainer

func (s *Service) StopContainer(ctx context.Context, containerID string) error

StopContainer 停止容器

type StoreApp

type StoreApp struct {
	ID            string      `json:"id"`
	Name          string      `json:"name"`
	Title         string      `json:"title"`
	Description   string      `json:"description"`
	TitleI18n     LocaleText  `json:"title_i18n"`
	DescI18n      LocaleText  `json:"description_i18n"`
	Category      string      `json:"category"`
	Icon          string      `json:"icon"`
	Version       string      `json:"version"`
	Author        string      `json:"author,omitempty"`
	License       string      `json:"license,omitempty"`
	Homepage      string      `json:"homepage"`
	Repository    string      `json:"repository"`
	Tags          []string    `json:"tags"`
	Architectures []string    `json:"architectures"`
	Form          []FormField `json:"form"`
	Compose       string      `json:"compose"` // YAML 字符串
}

StoreApp 商店应用(API 响应)

type StoreCategory

type StoreCategory struct {
	ID    string `json:"id"`
	Name  string `json:"name"`
	Count int    `json:"count"`
}

StoreCategory 商店分类

type StoreHandler

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

StoreHandler 应用商店 HTTP 处理器

func NewStoreHandler

func NewStoreHandler(catalog *CatalogService, logger *zap.Logger) *StoreHandler

NewStoreHandler 创建商店处理器

func (*StoreHandler) GetApp

func (h *StoreHandler) GetApp(c *gin.Context)

GetApp 获取应用详情 GET /docker/store/apps/:id

func (*StoreHandler) ListApps

func (h *StoreHandler) ListApps(c *gin.Context)

ListApps 获取应用列表 GET /docker/store/apps?category=xxx&search=xxx

func (*StoreHandler) ListCategories

func (h *StoreHandler) ListCategories(c *gin.Context)

ListCategories 获取分类列表 GET /docker/store/categories

func (*StoreHandler) RegisterRoutes

func (h *StoreHandler) RegisterRoutes(r *gin.RouterGroup)

RegisterRoutes 注册商店路由

func (*StoreHandler) SetIconsDir

func (h *StoreHandler) SetIconsDir(dir string)

SetIconsDir 设置图标目录路径

Jump to

Keyboard shortcuts

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