containerd: allow containers without an image
Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
parent
4d44b9358e
commit
27af417668
@ -48,9 +48,14 @@ var listCommand = cli.Command{
|
||||
w := tabwriter.NewWriter(os.Stdout, 10, 1, 3, ' ', 0)
|
||||
fmt.Fprintln(w, "ID\tIMAGE\tPID\tSTATUS")
|
||||
for _, c := range containers {
|
||||
image, err := c.Image(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
var imageName string
|
||||
if image, err := c.Image(ctx); err != nil {
|
||||
if err != containerd.ErrNoImage {
|
||||
return err
|
||||
}
|
||||
imageName = "-"
|
||||
} else {
|
||||
imageName = image.Name()
|
||||
}
|
||||
var (
|
||||
status string
|
||||
@ -73,7 +78,7 @@ var listCommand = cli.Command{
|
||||
}
|
||||
if _, err := fmt.Fprintf(w, "%s\t%s\t%d\t%s\n",
|
||||
c.ID(),
|
||||
image.Name(),
|
||||
imageName,
|
||||
pid,
|
||||
status,
|
||||
); err != nil {
|
||||
|
@ -3,7 +3,6 @@ package containerd
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
@ -17,7 +16,10 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var ErrNoRunningTask = errors.New("no running task")
|
||||
var (
|
||||
ErrNoImage = errors.New("container does not have an image")
|
||||
ErrNoRunningTask = errors.New("no running task")
|
||||
)
|
||||
|
||||
type Container interface {
|
||||
ID() string
|
||||
@ -96,7 +98,7 @@ func (c *container) Task(ctx context.Context, attach IOAttach) (Task, error) {
|
||||
// Image returns the image that the container is based on
|
||||
func (c *container) Image(ctx context.Context) (Image, error) {
|
||||
if c.c.Image == "" {
|
||||
return nil, fmt.Errorf("container is not based on an image")
|
||||
return nil, ErrNoImage
|
||||
}
|
||||
i, err := c.client.ImageService().Get(ctx, c.c.Image)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user