Skip to content

Commit 062844d

Browse files
Fix unsafe container cleanup in delete_image
Previously, delete_image stopped ALL containers on the system before removing the test image. This could interrupt unrelated containers. Now only stops and removes containers created from the specific test image being cleaned up. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
1 parent 455980a commit 062844d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

spec/spec_helper.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ def create_image(version)
1515

1616
def delete_image
1717
puts "Deleting image..."
18-
# Stop all containers so we can remove the image
19-
for container in Docker::Container.all(:all => true)
20-
container.stop
18+
# Stop and remove only containers created from this image
19+
Docker::Container.all(:all => true).each do |container|
20+
if container.info['Image'] == @image.id || container.info['ImageID'] == @image.id
21+
container.stop
22+
container.delete(:force => true)
23+
end
2124
end
2225

2326
@image.remove(:force => true)

0 commit comments

Comments
 (0)