I'm learning to use docker SDK. I understand that containers need to be removed after run, otherwise requiring pruning later on. I'm see that there are two boolean flags in client.containers.run
:
- auto_remove (bool) – enable auto-removal of the container on daemon side when the container’s process exits.
- remove (bool) – Remove the container when it has finished running. Default: False
What's the difference? If auto-remove is on daemon side
, which side is remove on? Angle? Which side should I join??
ref: https://docker-py.readthedocs.io/en/stable/containers.html
A Python library for the Docker Engine API. It lets you do anything the docker command does, but from within Python apps – run containers, manage containers, manage Swarms, etc. For more information about the Engine API, see its documentation.
It's in fact exactly that: AutoRemove
is one of the parameters to the "create a container" Docker API call, but the remove
option signals the client library to remove the container after it exits.
Setting auto_remove: True
is probably more robust (the container will still clean itself up if the coordinator process crashes) but if the container fails with that option set then container.run()
won't return its stderr. If you set detach: True
to get back a Container
object, then you can't use remove: True
(it gets converted to auto_remove: True
) but your code can container.remove()
it after it's exited.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With