Add ContainerService.Info to get info about a single container
For clients which only want to know about one container this is simpler than searching the result of execution.List. Signed-off-by: Ian Campbell <ian.campbell@docker.com>
This commit is contained in:
parent
660783cb00
commit
cc253b0f18
5 changed files with 291 additions and 57 deletions
44
cmd/ctr/info.go
Normal file
44
cmd/ctr/info.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
gocontext "context"
|
||||
"fmt"
|
||||
|
||||
"github.com/docker/containerd/api/services/execution"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var infoCommand = cli.Command{
|
||||
Name: "info",
|
||||
Usage: "get info about a container",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "id",
|
||||
Usage: "id of the container",
|
||||
},
|
||||
},
|
||||
Action: func(context *cli.Context) error {
|
||||
id := context.String("id")
|
||||
if id == "" {
|
||||
return errors.New("container id must be provided")
|
||||
}
|
||||
|
||||
containers, err := getExecutionService(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
response, err := containers.Info(gocontext.Background(), &execution.InfoRequest{ID: id})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
json, err := json.MarshalIndent(response, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(string(json))
|
||||
return nil
|
||||
},
|
||||
}
|
|
@ -44,6 +44,7 @@ containerd client
|
|||
eventsCommand,
|
||||
deleteCommand,
|
||||
listCommand,
|
||||
infoCommand,
|
||||
shimCommand,
|
||||
pprofCommand,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue