使用grpcurl调用containerd gRPC API遇未实现错误,求正确方法
问题
尝试使用以下grpcurl命令调用containerd的gRPC API:
.\grpcurl -plaintext -import-path "D:\github.com\containerd\api\services\containers\v1" -proto "D:\github.com\containerd\api\services\containers\v1\containers.proto" -d '{ \"filters\": \"k8s\" }' localhost:8080 containerd.services.containers.v1.Containers/List
收到错误响应:
ERROR: Code: Unimplemented Message: unknown service containerd.services.containers.v1.Containers
已确认ctr.exe可正常响应,gRPC服务处于运行状态,求正确的grpcurl调用方式。
解决方案
出现这个错误核心是端点地址、proto导入路径及请求格式存在问题,修正后即可正常调用:
1. 确认containerd的gRPC端点
containerd默认不监听localhost:8080:
- Windows系统默认使用命名管道:
npipe:////./pipe/containerd-containerd - Linux系统默认使用Unix域套接字:
/run/containerd/containerd.sock
如果没有手动修改配置,原命令中的localhost:8080是无效的。
2. 修正后的grpcurl命令
Windows系统下的正确命令:
grpcurl -plaintext -import-path "D:\github.com\containerd\api" -proto "D:\github.com\containerd\api\services\containers\v1\containers.proto" -d '{"filters": ["name~k8s"]}' npipe:////./pipe/containerd-containerd containerd.services.containers.v1.Containers/List
关键修正点:
- 导入路径调整:
-import-path需指向containerd api的根目录(D:\github.com\containerd\api),因为containers.proto依赖根目录下其他子目录的proto定义,仅指定单个服务目录会导致依赖解析失败。 - 请求数据格式修正:containerd的
filters参数要求是字符串数组,每个元素是标准过滤表达式(比如name~k8s表示模糊匹配名称包含k8s的容器),原命令直接传字符串"k8s"不符合API要求。 - 端点地址修正:替换为containerd默认的命名管道地址。
3. 验证可用服务(可选)
如果不确定当前暴露的gRPC服务,可先执行以下命令查看完整列表:
grpcurl -plaintext npipe:////./pipe/containerd-containerd list
执行后能看到containerd.services.containers.v1.Containers即为正常,说明服务已正确注册。
内容的提问来源于stack exchange,提问作者Rasheed
相关产品推荐
相关产品推荐

