“与命名卷不同,绑定安装不会自动将容器内容复制到主机上" [英] "a bind mount won't copy the container contents to the host automatically, unlike a named volume"
问题描述
Need clarity on a comment here:
绑定绑定的唯一问题"是它不会复制将容器中的内容自动发送到主机,这与命名卷不同.docs.docker.com/compose/compose-file/#volumes
The only 'problem' with a bind mount is that it won't copy the container contents to the host automatically, unlike a named volume. docs.docker.com/compose/compose-file/#volumes
这是准确的吗?如果是,则:
Is this accurate? If yes, then:
- 如何获取容器的新数据"?(例如,不断增长的数据库)在使用
- 在命名卷存在之前,Docker如何在容器重启期间持久保存数据?
bind挂载
(以便在容器重启时持久保存数据)时进入主机?- how does one get the container's "new data" (e.g. a growing database) into the host when using a
bind mount
(to persist the data in case of a container restart)? - how did Docker persist data across container restarts before there were
named volumes
?
推荐答案
我认为@BMitch接受的答案是正确的,但我只是尝试添加一些细节,希望有用.
I think @BMitch having the accepted answer is correct, but I will just try to add in some details with the hope of being useful.
这是准确的吗?如果是,则:
Is this accurate? If yes, then:
鉴于这是我的要求受到审查-我完全在这里@BMitch :)!但是我还要补充:
Given it is my claim being scrutinised - I totally defer to @BMitch here :)! However I would also add:
- https://github.com/docker/compose/issues/4581#issuecomment-389559090
- 为命名卷/主机卷的行为提供外行解释
- 我的解释需要更新以反映初始化"的概念
- 这是我建议现在由@kaiser提供的在docker-compose中设置卷的方式
如何获取容器的新数据"?(例如,不断增长的数据库)在使用绑定挂载(以在容器重新启动的情况下保留数据)时进入主机?
how does one get the container's "new data" (e.g. a growing database) into the host when using a bind mount (to persist the data in case of a container restart)?
主机卷和命名卷都可以实现这一目标.
Both host volumes and named volumes can achieve this.
我认为争论的焦点是您希望在以下事件上发生的事情:
I think the point of contention is what you want to happen on the:
- 容器的首次运行
- 容器的后续运行和
- 该卷在主机系统上的位置/可访问性.
一旦将卷连接到容器(无论是命名卷还是绑定安装),存储在该卷上的任何内容都应在两次重新启动之间保持不变-这实际上是免费的.假设使用相同的docker-compose配置,并且没有手动删除卷.
Once a volume is attached to a container (be it a named volume or bind mount), whatever is stored to that volume should be persisted between restarts - that effectively comes for free. This assumes the same docker-compose config, and no manual removal of volumes.
以前,使用命名卷有点限制,因为您无法记录日志,也不能像使用a那样轻松地直接从主机编辑代码 bind mount -但看来问题已解决/现在可以解决.
Previously it was a bit limiting using a named volume, as you couldn't tail logs, or edit code directly from the host as easily as you could with a bind mount - but it seems that problem is resolved / has a work around now.
绑定装载 能够在两次重启之间持久保存数据.我个人发现绑定卷可以在99%的时间内完成我想要的操作,也就是说,命名卷现在可以完成所有操作",而我会继续使用这些卷.
Bind mounts are able to persist data between restarts. I personally find that bind volumes do what I want 99% of the time, that being said, named volumes can now 'do it all' and I'd be using those moving forward.
尽管它们之间存在差异,但我敢肯定,他们偶尔还是会咬人,要求他们与实际专家联系,而不是像我这样的用户:).
There are differences between them though, and I'm sure they'll still bite people occasionally, requiring them to reach out to actual experts, instead of users like me :).
这篇关于“与命名卷不同,绑定安装不会自动将容器内容复制到主机上"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!