1

I have a docker-compose file where I define nginx, php, flask and each have volumes like this:

version: '3'

services:
  flask:
   ...
  volumes:
   ./foo:/foo/bar
  flask:
   ...
  volumes:
   ./foo:/foo/bar
  flask:
   ...
  volumes:
   ./foo:/foo/bar

So, my question is obvious. Is there a way to define one volume for the 3 services ONLY? There are other services that don't share the same volume, so is it possible to group services and give them one volume definition?

tegradite
  • 69
  • 7
  • You create a volume and give the volume name to these three services. With which you can share one volume for three services. Refer here. https://stackoverflow.com/questions/36387032/how-to-set-a-path-on-host-for-a-named-volume-in-docker-compose-yml/49920624#49920624 – Srini M Nov 19 '19 at 15:11

1 Answers1

3
 version: '3'

    services:
      flask1:
       .........
        volumes:
        - ./foo1:/foo1/bar
        - ./foo2:/foo2/bar
        - ./foo3:/foo3/bar

      flask2:
       .........
       volumes_from:
         - flask1

      flask3:
       .........
        volumes_from:
          - flask1

You can put several volumes in one service and then in another service invoke all of them. In the declaration of each service you must indicate the volumes you need, so you will always have to place at least two lines to declare them. Bye.