Named Volumes & Persistance in version 3
This is basically a question about named volumes. Starting from version 3 file format docker-compose does not allow volumes-from which was deprecated in favor of named volumes.
But there is a problem - with named volumes you cannot bind to local host folder & make it persistent. So, for example, if I want to share my project folder among nginx, fpm and mysql docker containers, I need to specify a volume mapping setting for each of them.
It's not possible to just create one named volume mapped to project folder & then simply reuse it in all containers.
Why this is not possible? I am aware of the third-party docker plugin like https://github.com/CWSpear/local-persist but as all third-party things, this does not make me feel I should use it (is it stable or maybe it is slow). Are there any particular reasons (drawbacks) why it was not implemented in the core?
One solution would be to declare each bind individually, like:
version: '3'
services:
mysql:
volumes:
- ./project:/opt/project
...
nginx:
volumes:
- ./project:/opt/project
...
fpm:
volumes:
- ./project:/opt/project
...
This is more explicit than using volumes_from, which might actually be a good thing.
On the other hand, why do your nginx and mysql services need access to your code?
@shin- the solution you describe is what I use now (and it seems not good for me, because of duplication & increased typoo possibility), but since V3 deprecated volumes-from, it means that docker team decided it's wrong approach.
There are scenarios where it is desirable to share one volume among multiple containers. For example nginx - to serve static content from project folder, fpm - to access both dynamic and static
Docker now says "use named volumes", but omits "persistence". Why is it?
If we don't use one volume per multiple containers we also have another issue - increased number of orphaned volumes after several successful/unsuccessful builds.
p.s.: also aware about docker system prune but that's not what I'd like to spend time every day
@rivaros I have the same problem. I also want to use named volume, but there seems to be no way to tell docker where to mount the volume from the host?
I'm having difficulty with this as well. With the updates to docker-compose in v3.2 and long-syntax there doesn't appear to be a way to have names/aliases for bind mounted volumes. It appears that the source is used for the name for volume mounted volumes, but the local path for bind mounted volumes...
With the removal of volumes_from support, I was wondering if it might be possible to define named volume support for bind mounted volumes, which would allow for single local path definition that can be shared between several services...
version: '3'
services:
web:
...
volumes:
- common_code
worker:
...
volumes:
- common_code
volumes:
- type: bind
name: common_code
source: /local/path
target: /application/path
It was mentioned that local-persist could be used as an approach to named local volumes, but I echo the question of why this isn't present in core. However, an approach like that would allow for even more nuanced behaviour like:
version: '3'
services:
worker:
...
volumes:
- common_code:/application/path
different-worker:
...
volumes:
- common_code:/different/application/path
volumes:
- type: bind
name: common_code
source: /local/path
Is there a reason we couldn't have named/aliased bind-type volume definitions inside the docker compose file?
Upvoting this again. Any comments from off team why it's not implemented?
Like @rivaros said in comment 299299853. Any comments?
We use docker configuration inside a sub folder of a git repository. This means we have nginx/php machines pointing to ../ and ../public/ We should be able to set that source folder in named volumes.
Then again, I'm not even seeing volumes mounted on the way @shin- described in comment 289867611
Months ago and still no answer from docker team? 😞
Hello,
Thanks for docker, but i agree with others, the volume from has no replacement now.
Applications which i use are in the same states that persons spoken before, we have :
- a app server container
- a command container
- a www server container
each of there works on the same data (assets, appfile, etc...). Traditionnal way to deploy, capistrano and same tools, don't works as they use many symbolic links not mounted by docker. The only way to deploy cleanly is consequently to use an image with data only, purge the volume on host and up the containers.
Another solution could be "use one container with all inside" : web server, app server, all cli command, but in this case why use docker ?
I think, the volume from or shared app data (code, assets aren't data, just the result of the build) should be reevaluated, maybe with just an option to volume, by example :
#...
volumes:
- type: volume
source: mydata
target: /data
volume:
copy_on: start # or up or empty or false
#...
Thanks for docker and docker-compose.
👍
Wowwwww!!! is almost 2018 and none has been assigned to this? This is a "must" since I am running into the same issue and there is a few workaround in this topic and out there but why haven't as part of the core? Upvoting this
How is this still not being implemented? At least I'd like to know an official workaround for this problem!
+100
+1
+1
Damn frustrating when using it for local development in complex orchestrations.
+1
+1
up vote!
+1
+1