Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,21 @@ def create_image(version)

def delete_image
puts "Deleting image..."
# Stop all containers so we can remove the image
for container in Docker::Container.all(:all => true)
container.stop
# Stop and remove only containers created from this image
Docker::Container.all(:all => true).each do |container|
container_image = container.info['Image']
container_image_id = container.info['ImageID']

# Match image IDs - container IDs may have sha256: prefix and be full hashes
# while @image.id is the short ID
if container_image&.include?(@image.id) || container_image_id&.include?(@image.id)
begin
container.stop unless container.info['State'] == 'exited'
container.delete(:force => true)
rescue Docker::Error::NotModifiedError
# Container already stopped, ignore
end
end
end

@image.remove(:force => true)
Expand Down