This commit is contained in:
hugues de keyzer 2025-06-27 19:05:40 -03:00 committed by GitHub
commit 65c9a434c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 2 deletions

View File

@ -894,7 +894,24 @@ class ContainerCollection(Collection):
stdout=stdout, stderr=stderr, stream=True, follow=True
)
exit_status = container.wait()['StatusCode']
if kwargs.get('auto_remove'):
wait_condition = 'removed'
else:
# the wait condition should theoretically be 'next-exit' (as is
# used by the cli), but it may have exited already if its run time
# was very short, which would cause the wait to hang.
# 'not-running' works in both cases.
wait_condition = 'not-running'
try:
exit_status = container.wait(condition=wait_condition)['StatusCode']
except NotFound:
if wait_condition == 'removed':
# it has been already removed, which is why it was not found,
# so everything fine here. unfortunately, there is no way to
# have its real exit status, so assume success.
exit_status = 0
else:
raise
if exit_status != 0:
out = None
if not kwargs.get('auto_remove'):

View File

@ -27,7 +27,9 @@ class ContainerCollectionTest(unittest.TestCase):
)
client.api.inspect_container.assert_called_with(FAKE_CONTAINER_ID)
client.api.start.assert_called_with(FAKE_CONTAINER_ID)
client.api.wait.assert_called_with(FAKE_CONTAINER_ID)
client.api.wait.assert_called_with(
FAKE_CONTAINER_ID, condition='not-running'
)
client.api.logs.assert_called_with(
FAKE_CONTAINER_ID, stderr=False, stdout=True, stream=True,
follow=True