简体   繁体   English

Docker命名卷与DOC(仅数据容器)

[英]Docker named volumes vs DOC (data-only-containers)

Up to recent version of Docker (v1.10), we were thought that we can use DOC: data-only containers . 直到最近版本的Docker(v1.10),我们认为我们可以使用DOC: 仅数据容器 So I would create such DOC (based on eg busybox) and use --volumes-from to link it to my container. 所以我会创建这样的DOC(基于例如busybox)并使用--volumes-from将它链接到我的容器。 You can still read about this in Docker documentation . 您仍然可以在Docker文档中阅读此内容

With new version of docker, it is said that instead of DOC we should use named volumes . 对于新版本的docker,我们应该使用named volumes来代替DOC。 Here is an example of docker-compose.yml : 这是docker-compose.yml一个例子:

version: '2'    
services:
  elasticsearch:
    image: elasticsearch:2.2.0
    command: elasticsearch -Des.network.host=0.0.0.0
    ports:
      - "9201:9200"
    volumes:
      - "es-data:/usr/share/elasticsearch/data"

volumes:    
  es-data:

Here we created and use named volume es-data . 在这里,我们创建并使用命名的卷es-data

There is still not much documentation on this new feature. 关于这个新功能的文档仍然不多。 I am asking: 我在问:

  • Can we replace DOC with named containers? 我们可以用命名容器替换DOC吗? How long volume is persisted? 音量持续多长时间? What if I remove the container that is using it? 如果我删除正在使用它的容器怎么办?
  • How can we eg backup now? 我们怎样才能备份呢? Previously, I could docker run --rm --volumes-from es-data ... and then tar it. 以前,我可以docker run --rm --volumes-from es-data ...然后tar它。

Can we replace DOC with named containers? 我们可以用命名容器替换DOC吗?

In many cases, yes, named containers will be a better option. 在许多情况下,是的,命名容器将是更好的选择。

How long volume is persisted? 音量持续多长时间? What if I remove the container that is using it? 如果我删除正在使用它的容器怎么办?

If you remove the container, the volume will still be there. 如果您卸下容器,卷仍将在那里。 The only way to remove the volume is to use docker-compose down -v or docker volume rm <volume name> . 删除卷的唯一方法是使用docker-compose down -vdocker volume rm <volume name>

How can we eg backup now? 我们怎样才能备份呢? Previously, I could docker run --rm --volumes-from es-data ... and then tar it. 以前,我可以从es-data中运行--rm --volumes - 然后tar它。

Instead of --volumes-from , you can use --volume=<volume name> . 而不是--volumes-from ,您可以使用--volume=<volume name>

Note that volumes created by docker-compose are always prefixed with the project name, so if you use it with a docker command the full name is actually <project_name>_es-data . 请注意,创建的卷docker-compose总是与项目名称前缀,所以如果你有一个使用docker命令的全称其实是<project_name>_es-data

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM