Docker Socket Proxy
Manages Docker containers via the tecnativa/docker-socket-proxy REST API using curl and jq. Which modes are available depends on which API sections the proxy instance has enabled.
Trigger conditions
- - User asks to list, start, stop, restart, kill, pause, or unpause a container or service
- User wants container logs, stats, top processes, or filesystem changes
- User asks about Docker images, networks, volumes, swarm services, or tasks
- A service needs to be restarted after a config change
Usage
CODEBLOCK0
Run with no arguments for full usage. Proxy URL is resolved from $DOCKER_PROXY_URL → $DOCKER_HOST (tcp→http) → http://localhost:2375.
Modes
System
| Mode | Description |
|---|
| INLINECODE6 | Health check |
| INLINECODE7 |
Docker version |
|
info | Host summary (containers, memory, etc.) |
|
events [--since T] [--until T] [--filters k=v] | Recent events (1s window) |
|
system-df | Disk usage by images/containers/volumes |
Containers
| Mode | Description |
|---|
| INLINECODE11 | Running containers |
| INLINECODE12 |
All containers including stopped |
|
inspect <name> | Full container details |
|
top <name> [ps-args] | Running processes inside container |
|
logs <name> [tail] | Container logs (default tail=100) |
|
stats <name> | CPU, memory, network, block I/O |
|
changes <name> | Filesystem changes since start |
|
start <name> | Start container |
|
stop <name> [timeout] | Stop container |
|
restart <name> [timeout] | Restart container |
|
kill <name> [signal] | Kill container (default SIGKILL) |
|
pause <name> | Pause container |
|
unpause <name> | Unpause container |
|
rename <name> <new-name> | Rename container |
|
exec <name> <cmd> [args...] | Run command in container |
|
prune-containers | Remove stopped containers |
Images
| Mode | Description |
|---|
| INLINECODE27 | List images |
| INLINECODE28 |
Image details |
|
image-history <name> | Layer history |
|
prune-images | Remove unused images |
Networks
| Mode | Description |
|---|
| INLINECODE31 | List networks |
| INLINECODE32 |
Network details and connected containers |
|
prune-networks | Remove unused networks |
Volumes
| Mode | Description |
|---|
| INLINECODE34 | List volumes |
| INLINECODE35 |
Volume details |
|
prune-volumes | Remove unused volumes |
Swarm
| Mode | Description |
|---|
| INLINECODE37 | Swarm info |
| INLINECODE38 |
List nodes |
|
node-inspect <name> | Node details |
|
services | List services |
|
service-inspect <name> | Service details |
|
service-logs <name> [tail] | Service logs |
|
tasks | List tasks |
|
configs | List configs |
|
secrets | List secrets |
Plugins
| Mode | Description |
|---|
| INLINECODE46 | List plugins |
Name matching
Container names can be partial — myapp matches project-myapp-1. Exact match is tried first, then substring. Errors clearly if 0 or 2+ containers match.
Notes
- - Modes that require disabled proxy sections (e.g.
IMAGES, NETWORKS, VOLUMES, SYSTEM) will return HTTP 403. This is expected — enable the relevant env var on the proxy to unlock them. - INLINECODE53 is two-step (create + start) and streams multiplexed output.
- INLINECODE54 uses a 1-second window by default; use
--since / --until to adjust.
Docker Socket Proxy
通过tecnativa/docker-socket-proxy REST API,使用curl和jq管理Docker容器。可用的模式取决于代理实例启用了哪些API部分。
触发条件
- - 用户要求列出、启动、停止、重启、杀死、暂停或恢复容器或服务
- 用户需要容器日志、统计信息、进程列表或文件系统变更
- 用户询问Docker镜像、网络、卷、Swarm服务或任务
- 配置变更后需要重启服务
使用方法
bash {baseDir}/scripts/run-docker.sh <模式> [参数...]
不带参数运行可查看完整用法。代理URL按以下顺序解析:$DOCKERPROXYURL → $DOCKER_HOST(tcp→http)→ http://localhost:2375。
模式
系统
Docker版本 |
| info | 主机摘要(容器、内存等) |
| events [--since T] [--until T] [--filters k=v] | 近期事件(1秒窗口) |
| system-df | 镜像/容器/卷的磁盘使用情况 |
容器
所有容器(包括已停止的) |
| inspect <名称> | 完整容器详情 |
| top <名称> [ps参数] | 容器内运行进程 |
| logs <名称> [行数] | 容器日志(默认行数=100) |
| stats <名称> | CPU、内存、网络、块I/O |
| changes <名称> | 自启动以来的文件系统变更 |
| start <名称> | 启动容器 |
| stop <名称> [超时] | 停止容器 |
| restart <名称> [超时] | 重启容器 |
| kill <名称> [信号] | 杀死容器(默认SIGKILL) |
| pause <名称> | 暂停容器 |
| unpause <名称> | 恢复容器 |
| rename <名称> <新名称> | 重命名容器 |
| exec <名称> <命令> [参数...] | 在容器中运行命令 |
| prune-containers | 移除已停止的容器 |
镜像
| 模式 | 描述 |
|---|
| images | 列出镜像 |
| image-inspect <名称> |
镜像详情 |
| image-history <名称> | 层历史 |
| prune-images | 移除未使用的镜像 |
网络
| 模式 | 描述 |
|---|
| networks | 列出网络 |
| network-inspect <名称> |
网络详情及连接的容器 |
| prune-networks | 移除未使用的网络 |
卷
| 模式 | 描述 |
|---|
| volumes | 列出卷 |
| volume-inspect <名称> |
卷详情 |
| prune-volumes | 移除未使用的卷 |
Swarm
列出节点 |
| node-inspect <名称> | 节点详情 |
| services | 列出服务 |
| service-inspect <名称> | 服务详情 |
| service-logs <名称> [行数] | 服务日志 |
| tasks | 列出任务 |
| configs | 列出配置 |
| secrets | 列出密钥 |
插件
名称匹配
容器名称可以是部分匹配——myapp可匹配project-myapp-1。优先尝试精确匹配,然后是子字符串匹配。如果匹配到0个或2个以上容器,会明确报错。
注意事项
- - 需要已禁用代理部分(如IMAGES、NETWORKS、VOLUMES、SYSTEM)的模式将返回HTTP 403。这是预期行为——在代理上启用相应的环境变量即可解锁。
- exec分两步执行(创建+启动),并流式传输多路复用输出。
- events默认使用1秒窗口;可使用--since/--until进行调整。