使用 commit docker 命令的最佳情况是什么?

What is the best case to use the commit docker command?

Docker 平台包含 commit 命令。

此命令可以通过容器创建图像,当我在官方指南中阅读此内容时,我想用数据提交数据库容器,但不支持此选项。

我的问题是: 使用 commit docker 命令的最佳情况是什么?

不确定是否有 "best case",但我会尽力回答。

当需要快速构建容器时,提交非常有用,因为编写 Dockerfile 通常比仅从 "within" 构建容器更耗时。提交使您能够在机器之间共享容器(通常通过 registry)。

至于你的句子...

I think to commit database container with data but this option is not supported.

这不完全正确,您确实可以在容器中提交数据库的数据。不过,我想您的数据库数据已装入卷中:

The commit operation will not include any data contained in volumes mounted inside the container.

Docker docs

因此,您可以将数据库数据放在拥有的目录中,而不是将数据库数据存储在主机而非容器中的卷装载中由容器而不是主机。然后,数据将包含在提交中。