With v2 of docker-compose synthax, we were able to do something like this:
version: '2'
services:
app:
image: tianon/true
volumes:
- ../app:/var/www/app
nginx:
image: nginx
volumes_from:
- app
php:
image: php
volumes_from:
- app
In v3.2 volumes_from
is now invalid option
. The documentation is all for using new top-level volumes synthax, which is all the ways better
.
I've read some comments on github, and the only solution that people propose is
version: '3.2'
services:
nginx:
image: nginx
volumes:
- app:/var/www/app
php:
image: php
volumes:
- app:/var/www/app
volumes:
app:
driver_opts:
type: none
device: ../app
o: bind
Which looks worse obviously, and it even doesn't work for me. It gives me an error: no such file or directory
. So what else should I try? It seems like I can still use links
instead of top-level volumes, but it's considered as legacy option in documentation. So how to do it right with new syntax?
EDIT: Question has been identified as a possible duplicate, but I don't agree. See my comment bellow for explanation.
As the topic starter already mentions, volumes_from
has been removed from the new docker-compose
syntax, according to the documentation in favour of named volumes defined in the top level key volumes
. The documentation also states the difference between volumes and bind mounts, one of which is who manages the contents:
By contrast, when you use a volume, a new directory is created within Docker’s storage directory on the host machine, and Docker manages that directory’s contents.
If this is the case, then it does not make sense to bind mount a host folder into a volume and let it be controlled by the host's file system and by Docker simultaneously.
If you still want to bind mount the same folder into two or more containers you could try something like:
version: '3.2'
services:
nginx:
image: nginx
volumes:
- type: bind
source: ../app
target: /var/www/app
php:
image: php
volumes:
- type: bind
source: ../app
target: /var/www/app
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With