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.
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:
Here we created and use named volume es-data
.
There is still not much documentation on this new feature. I am asking:
- 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.