Docker命名卷与DOC(仅数据容器) [英] Docker named volumes vs DOC (data-only-containers)
问题描述
直到最近版本的Docker(v1.10),我们以为可以使用DOC:仅数据的容器。因此,我将创建这样的DOC(基于例如busybox),并使用 - 卷从
链接到我的容器。您仍然可以在 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,据说,而不是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运行--rm --volumes - 从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吗? / p>
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< volume name>
。
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运行--rm --volumes - 从es数据...然后tar。
How can we e.g. backup now? Previously, I could docker run --rm --volumes-from es-data ... and then tar it.
而不是 - 卷从
,您可以使用 - 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屋!