How can I interact with containerd gRPC API using grpcurl?

Introduction

There is a CLI tool to interact with containerd called ctr. However I would like to achieve the same results without it using curl, after searching on google it can’t be done with curl but grpcurl instead.

How can I do basic gRPC calls to containerd?

What I have tried

First I downloaded both grpcurl and api.proto.

Then I listed available services:

vagrant@ubuntu-focal:~/containerd/api/grpc/types$ grpcurl -import-path . -proto api.proto list
types.API

vagrant@ubuntu-focal:~/containerd/api/grpc/types$ grpcurl -import-path . -proto api.proto list types.API
types.API.AddProcess
types.API.CreateCheckpoint
types.API.CreateContainer
types.API.DeleteCheckpoint
types.API.Events
types.API.GetServerVersion
types.API.ListCheckpoint
types.API.Signal
types.API.State
types.API.Stats
types.API.UpdateContainer
types.API.UpdateProcess

Used protoc to create a compiled version instead but didnt seem to change anything.

Finally tried making a request to the method Stats (including containerd’s UNIX socket path and -plaintext). However it seems I am messing something up, here is the error (both using --proto and --protoset:

sudo grpcurl -plaintext -protoset myservice.protoset -unix /run/containerd/containerd.sock types.API/Stats
ERROR:
  Code: Unimplemented
  Message: unknown service types.API

sudo grpcurl -plaintext -proto api.proto -unix /run/containerd/containerd.sock types.API.Stats
ERROR:
  Code: Unimplemented
  Message: unknown service types.API

Also tried with:

  • API/Stats
  • API.Stats
  • types.API.Stats

Read more here: Source link