Docker 命名卷与 DOC(仅数据容器) [英] Docker named volumes vs DOC (data-only-containers)
问题描述
在最新版本的 Docker (v1.10) 之前,我们认为我们可以使用 DOC:仅数据容器.所以我会创建这样的 DOC(基于例如 busybox)并使用 --volumes-from
将它链接到我的容器.您仍然可以在 Docker 文档一>.
Up to recent version of Docker (v1.10), we were thought that we can use DOC: data-only containers. So I would create such DOC (based on e.g. busybox) and use --volumes-from
to link it to my container. You can still read about this in Docker documentation.
在新版本的 docker 中,据说我们应该使用 named volumes
而不是 DOC.下面是一个 docker-compose.yml
的例子:
With new version of docker, it is said that instead of DOC we should use named volumes
. Here is an example of 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:
这里我们创建并使用了命名卷es-data
.
Here we created and use named volume es-data
.
关于这个新功能的文档仍然不多.我在问:
There is still not much documentation on this new feature. I am asking:
- 我们可以用命名容器替换 DOC 吗?音量持续多久?如果我移除正在使用它的容器会怎样?
- 我们如何才能例如立即备份?以前,我可以
docker run --rm --volumes-from es-data ...
然后tar
它.
- Can we replace DOC with named containers? How long volume is persisted? What if I remove the container that is using it?
- How can we e.g. backup now? Previously, I could
docker run --rm --volumes-from es-data ...
and thentar
it.
推荐答案
我们可以用命名容器替换 DOC 吗?
Can we replace DOC with named containers?
在很多情况下,是的,命名容器将是更好的选择.
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?
如果您移除容器,该卷仍将存在.删除卷的唯一方法是使用 docker-compose down -v
或 docker volume rm
.
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 run --rm --volumes-from es-data ... 然后 tar 它.
How can we e.g. backup now? Previously, I could docker run --rm --volumes-from es-data ... and then tar it.
您可以使用 --volume=
代替 --volumes-from
.
Instead of --volumes-from
, you can use --volume=<volume name>
.
请注意,docker-compose
创建的卷总是以项目名称为前缀,因此如果您将其与 docker
命令一起使用,则全名实际上是 <project_name>_es-data
.
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 命名卷与 DOC(仅数据容器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!