Delete rootfs when container is deleted

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
Derek McGowan 2017-05-15 17:38:12 -07:00
parent 3ae69c43d8
commit 4304da2b58
No known key found for this signature in database
GPG Key ID: F58C5D0A4405ACDB
2 changed files with 26 additions and 2 deletions

View File

@ -17,13 +17,26 @@ var deleteCommand = cli.Command{
if err != nil {
return err
}
snapshotter, err := getSnapshotter(context)
if err != nil {
return err
}
id := context.Args().First()
if id == "" {
return errors.New("container id must be provided")
}
_, err = containers.Delete(gocontext.Background(), &execution.DeleteRequest{
ctx := gocontext.TODO()
_, err = containers.Delete(ctx, &execution.DeleteRequest{
ID: id,
})
return err
if err != nil {
return errors.Wrap(err, "failed to delete container")
}
if err := snapshotter.Remove(ctx, id); err != nil {
return errors.Wrapf(err, "failed to remove snapshot %q", id)
}
return nil
},
}

View File

@ -127,6 +127,14 @@ var runCommand = cli.Command{
if err != nil {
return err
}
} else {
defer func() {
if id != "" {
if err := snapshotter.Remove(ctx, id); err != nil {
logrus.WithError(err).Errorf("failed to remove snapshot %q", id)
}
}
}()
}
ic, err := image.Config(ctx, content)
@ -206,6 +214,9 @@ var runCommand = cli.Command{
}); err != nil {
return err
}
} else {
// Don't remove snapshot
id = ""
}
if status != 0 {
return cli.NewExitError("", int(status))