Docker Community Forums

Share and learn in the Docker community.

What practical advantages do data volumes containers have over host directories as volumes and vice versa?


(John T. Wodder II) #1

Everyone’s always saying that, if you want to share data between containers, you should create a dedicated data container that is mounted with --volumes-from rather than using the -v /local/dir:/container/dir feature. Why? The only arguments for data volume containers seem to be stylistic (“more idiomatic/Dockerish”, “doesn’t ‘pollute’ non-Docker space with Docker”), while mounting a local directory at least avoids one form of human error (accidentally deleting the data container). As volumes are always saved on the local filesystem anyway, there doesn’t seem like there’d even be any technical difference between the two approaches. Why should one be favored over the other?


(Adhrick) #2

The advantage i see in my usage :

1.easy sharing of data (mostly configurations in my case) in multiple containers (3 instances of program with same config for instance)

  1. in my workflow : I deploy containers as opposed to containers + folders. I immediately see where data is coming from. Additional benefit is portability : i pull 2 containers (1 for service and 1 for data)
    on each new host.

  2. Prevent accidental deleting (or path changes) of data files, and i can store the data containers in my registry.

  3. Somewhat shorter commands
    I realize this is my usage and subjective. Just sharing why i use them

Hope that helps !


(Yenda) #3

It depends on using. If you mount a host directory into container, there is a disadvantage of ownership. If you have different users in the host system and container, docker doesn’t reflect it, just assigns UID. User with same UID in host system takes ownership of folders and files assigned to user UID from container!

On the other hand I wasn’t able to force Docker to allocate more space than implicit 100GB per container (basesize parameter may has a size limit). So if you want to share more space, mounting local host folder is probably only way - but be aware of syncing users!