Skip to content

Commit 825ac17

Browse files
author
hugues de keyzer
committed
fix waiting for auto_remove container
use the same logic as the cli to wait for the exit of a container when running one: ensure that a container run with auto_remove set to True has been removed when the function returns. this prevents a race condition when trying to run another container with the same name directly afterwards.
1 parent db7f8b8 commit 825ac17

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

docker/models/containers.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,11 @@ def run(self, image, command=None, stdout=True, stderr=False,
894894
stdout=stdout, stderr=stderr, stream=True, follow=True
895895
)
896896

897-
exit_status = container.wait()['StatusCode']
897+
if kwargs.get('auto_remove'):
898+
wait_condition = 'removed'
899+
else:
900+
wait_condition = 'next-exit'
901+
exit_status = container.wait(condition=wait_condition)['StatusCode']
898902
if exit_status != 0:
899903
out = None
900904
if not kwargs.get('auto_remove'):

0 commit comments

Comments
 (0)