What's the difference between auto_remove and remove in Docker SDK for python

Question:

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

Asked By: F.S.

||

Answers:

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.

Answered By: David Maze
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.