带有命名或匿名卷的“数据容器"-概念性问题?(讨论) [英] `data-container` with named or anonymous volumes - conceptual problems? (Discussion)

查看:21
本文介绍了带有命名或匿名卷的“数据容器"-概念性问题?(讨论)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用数据容器时,您可以使用这样的匿名卷

When using data-containers, you can either use anonymous volumes like this

version '2'
services:
  consumer:
    volume_from:
      - data-container:rw
  data-container:
    image: cogniteev/echo
    command: echo 'Data Container'
    volume:
      - /var/www

b) 命名卷

或者你可以像这样使用命名卷

b) Name volumes

or you can use named volumes like this

version '2'
services:
  consumer:
    volume_from:
      - data-container:rw
  data-container:
    image: cogniteev/echo
    command: echo 'Data Container'
    volume:
      - my-named-volume:/var/www

 volumes:
   my-named-volume:
     driver: local

我通常选择 b) 并想讨论/解释这两者的概念问题/缺陷.那么利弊是什么.

I usually go with b) and would like to discuss / get explained the conceptual issues / flaws of maybe both of those. So what are the pros and cons.

我们可以比较它们的方面是/可能是:

The aspects we can compare them against are / could be:

  1. 便携性
  2. 数据容器的可升级性(我们为什么要升级容器?)
  3. 启动/停止(继续)兼容性?
  4. 多堆栈问题?
  5. 效率(重复使用体积)

这个问题源于对这个问题的讨论https://stackoverflow.com/a/38984689/3625317

This question spwaned du to the discussion on this question https://stackoverflow.com/a/38984689/3625317

推荐答案

简短回答:首选命名数据卷,不再需要数据容器,因此永远不要在任何情况下使用 volumes-from新项目.

Short answer: named data volumes are preferred, data containers are no longer needed, so you should never use volumes-from on any new project.

您的命名卷版本正在合并命名和数据容器,它应该是:

Your version of named volumes is merging a named and data container, it should be:

version '2'
services:
  web:
    image: my-web-image
    volumes:
      - my-named-volume:/var/www

 volumes:
   my-named-volume:
     driver: local

通过合并两者,您添加了一个额外的间接层来访问您的命名卷,而没有任何额外的好处.命名卷是在 1.9 中创建的,以替换数据容器,这本身是一种有点被黑客入侵的方法提供持久数据.命名卷相对于数据容器的优势包括:

By merging the two, you've added an extra layer of indirection to reach your named volume, without any added benefits. Named volumes were created in 1.9 to replace data containers which were themselves a somewhat hacked method to provide persistent data. Advantages of named volumes over data containers include:

  • 您的数据管理与容器管理是分开的,您可以删除所有正在运行的容器,而您的数据仍然可用
  • 可以使用卷驱动程序将数据存储在不同的位置,这意味着您可以将其放在 nfs、分布式文件系统,甚至本地持久目录中
  • 你可以以任何顺序启动和停止任何容器,容器之间没有依赖关系
  • 当第一次创建时,命名卷将收到它首先安装在其上的映像文件系统的副本,与数据容器的行为相同,这意味着它是一个无缝转换(请注意,这不是主机卷,又名绑定挂载)

另见这个问题也讨论了命名卷与数据容器这个答案 另一个类似问题.我们还有一篇关于此的博文 由我工作的公司提供.

See also this question that also discusses named volumes vs data containers and this answer to another similar question. We also have a blog post on this by a company that I work for.

这篇关于带有命名或匿名卷的“数据容器"-概念性问题?(讨论)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆