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)
|
w := tabwriter.NewWriter(os.Stdout, 10, 1, 3, ' ', 0)
|
||||||
fmt.Fprintln(w, "ID\tIMAGE\tPID\tSTATUS")
|
fmt.Fprintln(w, "ID\tIMAGE\tPID\tSTATUS")
|
||||||
for _, c := range containers {
|
for _, c := range containers {
|
||||||
image, err := c.Image(ctx)
|
var imageName string
|
||||||
if err != nil {
|
if image, err := c.Image(ctx); err != nil {
|
||||||
return err
|
if err != containerd.ErrNoImage {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
imageName = "-"
|
||||||
|
} else {
|
||||||
|
imageName = image.Name()
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
status string
|
status string
|
||||||
@ -73,7 +78,7 @@ var listCommand = cli.Command{
|
|||||||
}
|
}
|
||||||
if _, err := fmt.Fprintf(w, "%s\t%s\t%d\t%s\n",
|
if _, err := fmt.Fprintf(w, "%s\t%s\t%d\t%s\n",
|
||||||
c.ID(),
|
c.ID(),
|
||||||
image.Name(),
|
imageName,
|
||||||
pid,
|
pid,
|
||||||
status,
|
status,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
|
@ -3,7 +3,6 @@ package containerd
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@ -17,7 +16,10 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"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 {
|
type Container interface {
|
||||||
ID() string
|
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
|
// Image returns the image that the container is based on
|
||||||
func (c *container) Image(ctx context.Context) (Image, error) {
|
func (c *container) Image(ctx context.Context) (Image, error) {
|
||||||
if c.c.Image == "" {
|
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)
|
i, err := c.client.ImageService().Get(ctx, c.c.Image)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user