gpt4 book ai didi

docker - 不使用卷的 docker 备份

转载 作者:行者123 更新时间:2023-12-02 11:40:41 24 4
gpt4 key购买 nike

我知道使用 docker 时的一般智慧是将数据移出容器并改用卷。

但我正在尝试创建一个提供一键式、完全容器化安装方法的系统,并且说“你应该先在你的计算机上安装 mongodb”不是一个选项。

所以当前的解决方案是将数据本身保存在容器中(例如 MongoDB),但我现在正在寻找不时备份容器本身快照的方法,以便我可以立即生成一个相同的容器当一个人倒下时从头开始。

我怎样才能做到这一点?

最佳答案

如果您不想使用卷,可以使用 docker commit --change "added some changes to my container" <container_id> repo/image:tag 在特定时间保存容器
新图像将包含您当前容器的所有文件系统。
话虽如此,不使用音量有几个缺点:
默认情况下,在容器内创建的所有文件都存储在可写容器层上。这意味着:

The data doesn’t persist when that container is no longer running, and it can be difficult to get the data out of the container if another process needs it.A container’s writable layer is tightly coupled to the host machine where the container is running. You can’t easily move the data somewhere else.Writing into a container’s writable layer requires a storage driver to manage the filesystem. The storage driver provides a union filesystem, using the Linux kernel. This extra abstraction reduces performance as compared to using data volumes, which write directly to the host filesystem.


所以你最好的选择是使用 volume !
现在您可以选择不同的种类:
  • 绑定(bind)坐骑
  • 命名卷

  • While bind mounts are dependent on the directory structure of the host machine, volumes are completely managed by Docker. Volumes have several advantages over bind mounts:

    Volumes are easier to back up or migrate than bind mounts.You can manage volumes using Docker CLI commands or the Docker API.Volumes work on both Linux and Windows containers.Volumes can be more safely shared among multiple containers.Volume drivers let you store volumes on remote hosts or cloud providers, to encrypt the contents of volumes, or to add other functionality.New volumes can have their content pre-populated by a container.


    阅读文档以更好地了解卷的功能: https://docs.docker.com/storage/volumes/

    关于docker - 不使用卷的 docker 备份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51708953/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com