0

EDIT: As stated in comments, solution can be found here


Using docker-compose I need to define a shared volume between 2 containers and host. In the example below, files shared between cont0 and cont1 need to be shared also with host.

Is it even possible what I'm trying to do? (The idea is that cont1 (and cont2) generate files that must be shared with cont0, but I want to easily access them from host).

This is the relevant part of a docker compose sharing volume C1 between cont0 and cont1, volume C2 between cont0 and cont2 and folder d of cont0 with host (folder D):

volumes:
  C1:
  C2

services:
  cont0:
    volumes:
      - ./D:/app/d
      - C1:/app/c1
      - C1:/app/c2

  cont1:
    volumes:
      - C1:/app/c

  cont2:
    volumes:
      - C2:/app/c

I now want to have folder E of host to hold data as folder c of cont0 and cont1 (or cont0 and cont2). I tried this:

  cont1:
    volumes:
      - ./E/c1:/app/c
      - C1:/app/c
  cont2:
    volumes:
      - ./E/c2:/app/c
      - C2:/app/c

but it failed to create the volume on the container definition (didn't even showed it on the docker-compose .... config

I then tried to do it from cont0 as:

  cont0:
    volumes:
      - ./D:/app/d
      - C1:/app/c1
      - C1:/app/c2
      - ./E/c1:/app/c1
      - ./E/c2:/app/c2

but it failed as well.

Qua285
  • 137
  • 1
  • 3
  • 12
  • Not marking as duplicate just yet, but does this help? https://stackoverflow.com/questions/44284484/docker-compose-share-named-volume-between-multiple-containers – Nick.Mc Feb 06 '22 at 21:50
  • @Nick.McDermaid Cheers mate, works like a charm. totally was not aware of that option. – Qua285 Feb 07 '22 at 14:50
  • 1
    maybe delete the question if your issue was solved or mark it as duplicate yourself. – The Fool Feb 07 '22 at 15:27
  • Right - I flagged it now as duplicated, cannot do more with my rights – Qua285 Feb 07 '22 at 16:17
  • Does this answer your question? [Docker Compose - Share named volume between multiple containers](https://stackoverflow.com/questions/44284484/docker-compose-share-named-volume-between-multiple-containers) – Nick.Mc Feb 13 '22 at 08:08

0 Answers0