a) Anonymous volumes
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) 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
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:
- portability
- upgradeability of the data-container (why would we ever upgrade the container ? )
- Start/Stop (continue) compatibility?
- multiple-stack issues?
- efficiency ( reuse of the volume )
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:
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:
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.