Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

docker

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

like image 553
F.S. Avatar asked Jan 11 '20 00:01

F.S.


People also ask

What is docker SDK for Python?

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.


1 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.

like image 81
David Maze Avatar answered Oct 16 '22 12:10

David Maze