# docker-monitor **Repository Path**: gcjh/docker-monitor ## Basic Information - **Project Name**: docker-monitor - **Description**: Docker Monitor 是一个用于监控和管理 Docker 容器的 Web 应用程序。它提供了一个直观的用户界面,可以查看容器状态、启动/停止/重启容器、查看容器日志 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-09-19 - **Last Updated**: 2025-09-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Docker Monitor Docker Monitor 是一个用于监控和管理 Docker 容器的 Web 应用程序。它提供了一个直观的用户界面,可以查看容器状态、启动/停止/重启容器、查看容器日志等操作。 ## 功能特点 - 实时查看所有 Docker 容器的状态(运行中、已停止等) - 启动、停止、重启和删除容器 - 查看容器详细信息(端口映射、挂载卷、PID等) - 查看容器日志 - 响应式 Web 界面,支持桌面和移动设备 - 刷新功能以获取最新容器状态 ## 技术栈 - Go 语言后端 - Docker API 进行容器管理 - Bootstrap 5 和 Bootstrap Icons 构建前端界面 - Gorilla Mux 路由库 ## 安装和运行 ### 先决条件 - Go 1.24 或更高版本 - Docker 已安装并正在运行 - Docker 守护进程需要允许 API 访问 ### 安装步骤 1. 克隆仓库: ```bash git clone cd docker-monitor ``` 2. 初始化 Go 模块: ```bash go mod tidy ``` 3. 编译程序: ```bash go build -o docker-monitor ``` 4. 运行程序(默认使用8080端口运行HTTP服务器,8081端口运行MCP服务器): ```bash ./docker-monitor ``` 在 Windows 上: ```bash docker-monitor.exe ``` 您也可以通过命令行参数指定端口: ```bash # 在 Linux/Mac 上 ./docker-monitor --port 8082 --mcpport 8083 # 在 Windows 上 docker-monitor.exe --port 8082 --mcpport 8083 ``` 参数说明: - `--port`: 设置HTTP服务器端口(默认为8080) - `--mcpport`: 设置MCP服务器端口(默认为8081) ### 使用 Docker 运行 您也可以使用 Docker 来运行此应用程序: ```bash docker build -t docker-monitor . docker run -d -p 8080:8080 -v /var/run/docker.sock:/var/run/docker.sock docker-monitor ``` ## 使用方法 1. 启动应用程序后,在浏览器中访问 `http://localhost:8080` 2. 主界面将显示所有 Docker 容器的列表 3. 可以使用每个容器卡片上的按钮来管理容器: - **Details**: 查看容器详细信息 - **Stop**: 停止正在运行的容器 - **Start**: 启动已停止的容器 - **Restart**: 重启容器 - **Remove**: 删除容器 4. 点击右上角的刷新按钮以获取最新的容器状态 ## API 接口 应用程序提供以下 RESTful API 接口: - `GET /api/v1/containers` - 获取所有容器列表 - `GET /api/v1/containers/{id}` - 获取特定容器的详细信息 - `POST /api/v1/containers/{id}/start` - 启动容器 - `POST /api/v1/containers/{id}/stop` - 停止容器 - `POST /api/v1/containers/{id}/restart` - 重启容器 - `DELETE /api/v1/containers/{id}` - 删除容器 - `GET /api/v1/containers/{id}/logs` - 获取容器日志 ## Management Control Plane (MCP) 接口 MCP接口为AI模型和自动化工具提供了基于JSON-RPC 2.0的结构化容器管理API: ### JSON-RPC 2.0端点 - `POST /mcp/rpc` - JSON-RPC 2.0端点,支持所有MCP功能 ### 核心SSE端点 - `GET /mcp/events` - 获取所有MCP事件的实时流 - `GET /mcp/events/containers` - 获取所有容器的实时事件流(已弃用) - `GET /mcp/events/containers/{id}` - 获取特定容器的实时事件流(已弃用) ### MCP方法 通过 `/mcp/rpc` 端点可以调用以下方法: - `tools/list` - 获取可用工具列表 - `prompts/list` - 获取提示模板列表 - `resources/list` - 获取相关资源列表 - `tools/call` - 调用特定工具 ### 使用方法 ```bash # 获取工具列表(使用默认端口) curl -X POST http://localhost:8080/mcp/rpc \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "method": "tools/list", "id": 1 }' # 调用工具(使用默认端口) curl -X POST http://localhost:8080/mcp/rpc \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "method": "tools/call", "params": { "name": "list_containers" }, "id": 2 }' # 获取特定容器信息(使用默认端口) curl -X POST http://localhost:8080/mcp/rpc \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "method": "tools/call", "params": { "name": "get_container", "arguments": { "container_id": "container_id_here" } }, "id": 3 }' ``` JSON-RPC 2.0接口为AI模型提供实时的上下文信息和容器状态监控能力,并支持双向通信。 ### 工具列表 (`tools/list`) 为AI模型提供可用工具的列表,包括工具名称、描述和参数信息: ```json [ { "name": "list_containers", "description": "List all Docker containers with their status and details" }, { "name": "get_container", "description": "Get detailed information about a specific container", "inputSchema": { "type": "object", "properties": { "container_id": { "type": "string", "description": "The ID of the container to get information for" } }, "required": ["container_id"] } }, ... ] ``` ### 提示模板 (`prompts/list`) 为AI模型提供预定义的提示模板,帮助生成特定类型的响应: ```json [ { "name": "container_status_summary", "description": "Generate a summary of container statuses", "arguments": { "container_id": "The ID of a specific container to summarize (optional)" } }, ... ] ``` ### 资源列表 (`resources/list`) 为AI模型提供相关资源的链接,包括官方文档和其他有用信息: ```json [ { "uri": "https://docs.docker.com/", "name": "Docker Documentation", "description": "Official Docker documentation for container management", "mimeType": "text/html" }, ... ] ``` ### 事件流 通过 `/mcp/events` 端点可以监听实时事件流: ```bash # 监听事件流(使用默认端口) curl -N -H "Accept:text/event-stream" http://localhost:8080/mcp/events # 如果使用自定义端口运行程序,需要相应调整URL # 例如使用8082作为HTTP端口和8083作为MCP端口 # curl -N -H "Accept:text/event-stream" http://localhost:8082/mcp/events ``` 事件类型包括: - `tools/list` - 工具列表更新 - `prompts/list` - 提示模板更新 - `resources/list` - 资源列表更新 - `initialize` - 初始化事件 - `initialized` - 初始化完成事件 - `progress` - 进度事件 - `logging/message` - 日志消息事件 - `ping` - 心跳事件 ## 项目结构 ``` docker-monitor/ ├── main.go # 程序入口点 ├── go.mod # Go 模块定义 ├── go.sum # Go 模块校验和 ├── internal/ │ ├── api/ # API 路由处理 │ ├── docker/ # Docker 服务接口 │ ├── web/ # Web 界面处理 │ └── mcp/ # MCP 相关功能 └── README.md # 项目说明文档 ``` ## 开发 要为项目做贡献,请遵循以下步骤: 1. Fork 仓库 2. 创建功能分支 (`git checkout -b feature/AmazingFeature`) 3. 提交更改 (`git commit -m 'Add some AmazingFeature'`) 4. 推送到分支 (`git push origin feature/AmazingFeature`) 5. 开启 Pull Request ## 许可证 本项目采用 MIT 许可证。详情请见 [LICENSE](LICENSE) 文件。 ## 联系方式 项目链接: [https://github.com/your-username/docker-monitor](https://github.com/your-username/docker-monitor)