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:
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
|
||||
},
|
||||
}
|
Reference in New Issue
Block a user