Skip to content

Commit bc9f0b8

Browse files
Merge pull request #13564 from eszense/rmi-patch
docker/provider: handle variation in error text during image removal
2 parents 6cab680 + 6729d25 commit bc9f0b8

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

plugins/providers/docker/driver.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,9 @@ def rmi(id)
225225
execute('docker', 'rmi', id)
226226
return true
227227
rescue => e
228-
return false if e.to_s.include?("is using it")
229-
return false if e.to_s.include?("is being used")
228+
return false if e.to_s.include?("is using it") or
229+
e.to_s.include?("is being used") or
230+
e.to_s.include?("is in use")
230231
raise if !e.to_s.include?("No such image")
231232
end
232233

test/unit/plugins/providers/docker/driver_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,15 @@
579579
subject.rmi(id)
580580
end
581581
end
582+
583+
context 'image is in use by a container' do
584+
before { allow(subject).to receive(:execute).and_raise("image is in use by a container") }
585+
586+
it 'does not remove the image' do
587+
expect(subject.rmi(id)).to eq(false)
588+
subject.rmi(id)
589+
end
590+
end
582591
end
583592

584593
describe '#inspect_container' do

0 commit comments

Comments
 (0)