-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using docker.client.DockerClient.containers.run with auto_remove=True causes a crash #1813
Comments
+1
|
This problem is not totally resolved by #1836 . I can still reproduce this issue with current master code.
I think there are still two problems with the code when # docker/models/containers.py
725 container.start()
726
727 if detach:
728 return container
729
730 logging_driver = container.attrs['HostConfig']['LogConfig']['Type']
731
732 out = None
733 if logging_driver == 'json-file' or logging_driver == 'journald':
# the container may have already been removed if it exited too fast,
# just like my above example, cause logs() to fail with NotFound.
734 out = container.logs(
735 stdout=stdout, stderr=stderr, stream=True, follow=True
736 )
737
738 exit_status = container.wait()
739 if exit_status != 0:
# after wait(), container was already removed, thus this logs()
# call will certainly fail with NotFound.
740 out = container.logs(stdout=False, stderr=True) |
Hi, @StephenPCG. I usually use |
Thanks guys. As @feliperuhland points out, if you're interested in the container's output, you probably want to use That said, I submitted #1840 to make sure we don't attempt to get the logs after the |
@feliperuhland @shin- Thank you for pointing that out! I didn't realize there is a |
Been running into this issue too. I've been using the container = client.containers.run(
image="image",
command="commands...",
remove=True,
detach=True,
)
result = container.wait()
if result["StatusCode"] != 0:
raise Exception("My exception") |
What happens is straightforward: setting auto_remove=True in the arguments to run() causes the container to be removed before the Python client attempts to read the logs. This then raises an error like:
This is not how executing
docker run -rm
works, where the output still goes to stdout, and it means that calling run() with auto_remove=True isn't useful.The text was updated successfully, but these errors were encountered: