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

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

问题描述

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

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. 效率(重用该卷)

  1. portability
  2. upgradeability of the data-container (why would we ever upgrade the container ? )
  3. Start/Stop (continue) compatibility?
  4. multiple-stack issues?
  5. efficiency ( reuse of the volume )

这个问题涉及到关于这个问题的讨论 https://stackoverflow.com/a / 38984689/3625317

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

推荐答案

简答:命名数据卷是首选,不再需要数据容器您不应该在任何新项目中使用中的卷。

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,分布式文件系统或甚至本地持久目录下

  • 您可以按任何顺序启动和停止任何容器,而不需要容器之间的依赖关系

  • 首次创建时,命名卷将收到首次安装的映像文件系统的副本与数据容器的行为相同,这意味着它是一个无缝转换(请注意,这不是主机卷的行为,也就是bind mount)

  • Your data management is separate from your container management, you can remove all running containers and still have your data available
  • Data can be stored in different locations using volume drivers, which means you can put it on nfs, a distributed file system, or even a local persistent directory
  • You may start and stop any container in any order without dependencies between containers
  • When first created, a named volume will receive a copy of the image filesystem it is first mounted on top of, identical to the behavior of data containers, which means it's a seamless transition (note that this is not the behavior of a host volume, aka bind mount)

另请参见此问题还讨论了命名卷与数据容器这个答案另一个类似的问题。我们还有一个此博客文章由我所在的公司。

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天全站免登陆