docker-compose v3: sharing bind-mounted volume between multiple containers with top-level volumes syntax

Viewed 7661

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.

1 Answers
Related