From 0b6ba1cd32fc2a7041cc4a9fd7a54a15d7eee3a9 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Fri, 16 Jul 2021 12:00:27 -0700 Subject: [PATCH] don't error on deleting old build containers without state volume Signed-off-by: Tonis Tiigi --- driver/docker-container/driver.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/driver/docker-container/driver.go b/driver/docker-container/driver.go index a0b261d722f..d240b04a00b 100644 --- a/driver/docker-container/driver.go +++ b/driver/docker-container/driver.go @@ -275,15 +275,24 @@ func (d *Driver) Rm(ctx context.Context, force bool, rmVolume bool) error { return err } if info.Status != driver.Inactive { + container, err := d.DockerAPI.ContainerInspect(ctx, d.Name) + if err != nil { + return err + } if err := d.DockerAPI.ContainerRemove(ctx, d.Name, dockertypes.ContainerRemoveOptions{ RemoveVolumes: true, Force: force, }); err != nil { return err } - if rmVolume { - return d.DockerAPI.VolumeRemove(ctx, d.Name+volumeStateSuffix, false) + for _, v := range container.Mounts { + if v.Name == d.Name+volumeStateSuffix { + if rmVolume { + return d.DockerAPI.VolumeRemove(ctx, d.Name+volumeStateSuffix, false) + } + } } + } return nil }