Docker SDK for python中的auto_remove和remove有什么区别

2024-06-17 03:57:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在学习使用docker SDK。我知道运行后需要删除容器,否则以后需要修剪。我看到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

有什么区别?如果自动删除on daemon side,则删除在哪一侧?角我应该加入哪一方


参考:https://docker-py.readthedocs.io/en/stable/containers.html


Tags: thedockerrunclientautooncontainersdk
1条回答
网友
1楼 · 发布于 2024-06-17 03:57:21

事实上:AutoRemove确实是"create a container" Docker API call的参数之一,但是remove选项向remove the container after it exits发送客户端库的信号

设置auto_remove: True可能更健壮(如果协调进程崩溃,容器仍将自行清理),但如果容器在设置该选项时失败,则^{} won't return its stderr。如果将detach: True设置为返回Container对象,则不能使用remove: True(它获取converted to ^{}),但代码可以在退出后container.remove()返回它

相关问题 更多 >