@@ -11,19 +11,19 @@ import (
1111 "github.com/docker/engine-api/client"
1212)
1313
14- // CmdInspect displays low-level information on one or more containers or images .
14+ // CmdInspect displays low-level information on one or more containers, images or tasks .
1515//
16- // Usage: docker inspect [OPTIONS] CONTAINER|IMAGE [CONTAINER|IMAGE...]
16+ // Usage: docker inspect [OPTIONS] CONTAINER|IMAGE|TASK [CONTAINER|IMAGE|TASK ...]
1717func (cli * DockerCli ) CmdInspect (args ... string ) error {
18- cmd := Cli .Subcmd ("inspect" , []string {"CONTAINER|IMAGE [CONTAINER|IMAGE...]" }, Cli .DockerCommands ["inspect" ].Description , true )
18+ cmd := Cli .Subcmd ("inspect" , []string {"CONTAINER|IMAGE|TASK [CONTAINER|IMAGE|TASK ...]" }, Cli .DockerCommands ["inspect" ].Description , true )
1919 tmplStr := cmd .String ([]string {"f" , "-format" }, "" , "Format the output using the given go template" )
20- inspectType := cmd .String ([]string {"-type" }, "" , "Return JSON for specified type, (e.g image or container )" )
20+ inspectType := cmd .String ([]string {"-type" }, "" , "Return JSON for specified type, (e.g image, container or task )" )
2121 size := cmd .Bool ([]string {"s" , "-size" }, false , "Display total file sizes if the type is container" )
2222 cmd .Require (flag .Min , 1 )
2323
2424 cmd .ParseFlags (args , true )
2525
26- if * inspectType != "" && * inspectType != "container" && * inspectType != "image" {
26+ if * inspectType != "" && * inspectType != "container" && * inspectType != "image" && * inspectType != "task" {
2727 return fmt .Errorf ("%q is not a valid value for --type" , * inspectType )
2828 }
2929
@@ -35,6 +35,11 @@ func (cli *DockerCli) CmdInspect(args ...string) error {
3535 elementSearcher = cli .inspectContainers (ctx , * size )
3636 case "image" :
3737 elementSearcher = cli .inspectImages (ctx , * size )
38+ case "task" :
39+ if * size {
40+ fmt .Fprintln (cli .err , "WARNING: --size ignored for tasks" )
41+ }
42+ elementSearcher = cli .inspectTasks (ctx )
3843 default :
3944 elementSearcher = cli .inspectAll (ctx , * size )
4045 }
@@ -54,6 +59,12 @@ func (cli *DockerCli) inspectImages(ctx context.Context, getSize bool) inspect.G
5459 }
5560}
5661
62+ func (cli * DockerCli ) inspectTasks (ctx context.Context ) inspect.GetRefFunc {
63+ return func (ref string ) (interface {}, []byte , error ) {
64+ return cli .client .TaskInspectWithRaw (ctx , ref )
65+ }
66+ }
67+
5768func (cli * DockerCli ) inspectAll (ctx context.Context , getSize bool ) inspect.GetRefFunc {
5869 return func (ref string ) (interface {}, []byte , error ) {
5970 c , rawContainer , err := cli .client .ContainerInspectWithRaw (ctx , ref , getSize )
@@ -63,7 +74,15 @@ func (cli *DockerCli) inspectAll(ctx context.Context, getSize bool) inspect.GetR
6374 i , rawImage , err := cli .client .ImageInspectWithRaw (ctx , ref , getSize )
6475 if err != nil {
6576 if client .IsErrImageNotFound (err ) {
66- return nil , nil , fmt .Errorf ("Error: No such image or container: %s" , ref )
77+ // Search for task with that id if an image doesn't exists.
78+ t , rawTask , err := cli .client .TaskInspectWithRaw (ctx , ref )
79+ if err != nil {
80+ return nil , nil , fmt .Errorf ("Error: No such image, container or task: %s" , ref )
81+ }
82+ if getSize {
83+ fmt .Fprintln (cli .err , "WARNING: --size ignored for tasks" )
84+ }
85+ return t , rawTask , nil
6786 }
6887 return nil , nil , err
6988 }
0 commit comments