我希望能够在退出后容易地清理容器。 这是可能的远程API? (除了发现我自己退出并使用DELETE / containers端点删除之外)
I'd like to be able to easily clean up containers after they exit. Is this possible with the remote API? (Other than discovering the exit myself and removing with the DELETE/containers endpoint)
最满意答案
Docker客户端中的--rm选项完全是客户端选项。 例如,这是为什么你不能将-d和--rm结合起来,因为如果客户端保持连接到容器,客户端只能在退出时移除容器。
您可以编写一个清理脚本,定期运行docker ps -f status=exited -q并清理结果。
我猜,你也可以通过监视Docker API /events端点并立即响应容器退出来实现更多的自动化。
The --rm option in the Docker client is entirely a client side option. This is, for example, why you can't combine -d with --rm -- because the client is only able to remove the container on exit if it stays attached to the container.
You could write a clean up script that would periodically run docker ps -f status=exited -q and clean up the result.
You could also achieve something more automated by monitoring the Docker API's /events endpoint and responding immediately to container exits, I guess.
Docker远程API是否具有与“docker run --rm ...”等效的功能?(Does the Docker remote API have an equivalent for “docker run --rm …”?)我希望能够在退出后容易地清理容器。 这是可能的远程API? (除了发现我自己退出并使用DELETE / containers端点删除之外)
I'd like to be able to easily clean up containers after they exit. Is this possible with the remote API? (Other than discovering the exit myself and removing with the DELETE/containers endpoint)
最满意答案
Docker客户端中的--rm选项完全是客户端选项。 例如,这是为什么你不能将-d和--rm结合起来,因为如果客户端保持连接到容器,客户端只能在退出时移除容器。
您可以编写一个清理脚本,定期运行docker ps -f status=exited -q并清理结果。
我猜,你也可以通过监视Docker API /events端点并立即响应容器退出来实现更多的自动化。
The --rm option in the Docker client is entirely a client side option. This is, for example, why you can't combine -d with --rm -- because the client is only able to remove the container on exit if it stays attached to the container.
You could write a clean up script that would periodically run docker ps -f status=exited -q and clean up the result.
You could also achieve something more automated by monitoring the Docker API's /events endpoint and responding immediately to container exits, I guess.
发布评论