Skip to content

Commit

Permalink
Merge pull request #676 from tonistiigi/vol-delete
Browse files Browse the repository at this point in the history
don't error on deleting old build containers without state volume
  • Loading branch information
tonistiigi authored Jul 16, 2021
2 parents 65a6955 + 0b6ba1c commit d9ee3b1
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions driver/docker-container/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit d9ee3b1

Please sign in to comment.