我正在学习使用 docker SDK。我知道容器需要在运行后删除,否则需要稍后进行修剪。我看到 client.containers.run
中有两个 bool 标志:
- 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
有什么区别?如果自动删除位于守护进程端
,那么删除位于哪一侧?天使?我应该加入哪一边?
引用:https://docker-py.readthedocs.io/en/stable/containers.html
最佳答案
事实上正是这样:AutoRemove
是"create a container" Docker API call 的参数之一。 ,但 remove
选项向客户端库发出信号 remove the container after it exits .
设置 auto_remove: True
可能更稳健(如果协调器进程崩溃,容器仍会自行清理),但如果容器因设置该选项而失败,则 container.run()
won't return its stderr 。如果您设置 detach: True
来取回 Container
对象,则无法使用 remove: True
(它会获取 converted to auto_remove: True
)但您的代码可以在退出后container.remove()
它。
关于python - Docker SDK for python中的auto_remove和remove有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59690457/