Docker-compose v3: sharing connected volume between multiple containers with top-level volume syntax

With v2 synthax creating dockers, 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_fromnow invalid option. The documentation is intended to use the new syntax of the top-level volumes that make up all the ways better. I read some comments on github, and the only solution that man offers 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 clearly worse, and it doesn't even work for me. It gives me an error: no such file or directory. So what else should I try? It looks like I can still use linkstop-level volumes instead, but in the documentation it is deprecated. So how to do this with the new syntax?

EDIT: , . . .

+4
1

, volumes_from docker-compose, , volumes. volumes bind mounts, :

Dockers , Docker .

, - .

, - :

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
0

Source: https://habr.com/ru/post/1680410/


All Articles