getDockerInfo
Retrieve detailed Docker information for the current operating environment. Returns empty if Docker is not installed, aiding quick environment checks.
Instructions
获取当前设备的 Docker 信息,若未安装则返回空
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"properties": {},
"required": [],
"type": "object"
}
Implementation Reference
- src/index.ts:262-270 (registration)Registration of the getDockerInfo tool in the listTools response, including name, description, and input schema.{ name: "getDockerInfo", description: "获取当前设备的 Docker 信息,若未安装则返回空", inputSchema: { type: "object", properties: {}, required: [] } },
- src/index.ts:714-740 (handler)Handler function for getDockerInfo tool. Checks if Docker is installed, fetches Docker version, images, and all containers using docker CLI commands, parses the output, and returns JSON-formatted info or empty object if not installed.case "getDockerInfo": { let dockerInfo = {}; try { // 检查 Docker 是否安装 execSync('docker --version'); // 获取 Docker 信息 const dockerVersion = execSync('docker version --format \'{{json .}}\'').toString(); const dockerImages = execSync('docker images --format \'{{json .}}\'').toString().split('\n').filter(Boolean).map(line => JSON.parse(line)); const dockerContainers = execSync('docker ps -a --format \'{{json .}}\'').toString().split('\n').filter(Boolean).map(line => JSON.parse(line)); dockerInfo = { version: JSON.parse(dockerVersion), images: dockerImages, containers: dockerContainers }; } catch (error) { // Docker 未安装或者出错,返回空对象 dockerInfo = {}; } return { content: [{ type: "text", text: JSON.stringify(dockerInfo, null, 2) }] }; }