Sharing host volumes without volumes_from in compose version 3 between services

With version 2 syntax I had something like this:

services:
    web:
        image: nginx
        volumes_from:
            - php:ro
    php:
        image: custom/image
        volumes:
           - .:/var/www

I’m totally clueless how can this be done with version 3 syntax.

In the top level volumes I cannot find any option to make volume directory shared with the host.

Is this feature gone and I should go for:

services:
    web:
        image: nginx
        volumes_from:
           - .:/var/www:ro
    php:
        image: custom/image
        volumes:
           - .:/var/www

compose version 3 is not meant to be used with host volumes, more with distributed volumes.

in your first case, with simple sharing, you just need to explicit define a named volume and use this volume in your php as well as in your web service.

if you then explicit need that this named volume is written to your local host, you can use the driver local-persist.

Thank you for your response.

But if I’m not mistaken local-persist is 3rd party plugin. With simple, default installation it won’t work.

it allows you to specify the host-directory it should mount. Otherwise it will be somewhere under /var/lib/docker/volumes…

Named volumes are the way to go. Host mounting creates an undesirable coupling which severely limits the ability of your scheduler to locate containers (even when that scheduler is you). For obvious reasons stateless containers are preferable, but of course in reality we do need to deal with application persistent storage. If you can do that off a physical host, either using a network storage driver or a database, then the life-cycle of your containerised estate will become infinitely easier to manage.