Skip to content

Commit 550b002

Browse files
committed
Fix container matching to handle sha256: prefix in image IDs
The container Image and ImageID fields contain full SHA256 hashes with 'sha256:' prefix, while @image.id is the short 12-character ID. Changed from exact equality checks to substring matching using include?().
1 parent bc61990 commit 550b002

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

spec/spec_helper.rb

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,14 @@ def create_image(version)
1515

1616
def delete_image
1717
puts "Deleting image..."
18-
puts "Image ID to delete: #{@image.id}"
19-
2018
# Stop and remove only containers created from this image
2119
Docker::Container.all(:all => true).each do |container|
2220
container_image = container.info['Image']
2321
container_image_id = container.info['ImageID']
2422

25-
puts "Container #{container.id[0..11]}: Image=#{container_image}, ImageID=#{container_image_id}"
26-
27-
# Match both short and long image IDs
28-
if container_image == @image.id ||
29-
container_image == @image.id[0..11] ||
30-
container_image_id == @image.id ||
31-
container_image_id == @image.id[0..11]
32-
puts " -> Matches! Removing container #{container.id[0..11]}"
23+
# Match image IDs - container IDs may have sha256: prefix and be full hashes
24+
# while @image.id is the short ID
25+
if container_image&.include?(@image.id) || container_image_id&.include?(@image.id)
3326
begin
3427
container.stop unless container.info['State'] == 'exited'
3528
container.delete(:force => true)

0 commit comments

Comments
 (0)