-1
  • I have two local folders, the content of both is bind mounted into their own containers.

  • I also have the same named volume mounted to both in attempt to share files between containers while also bind mounting to local folders and keeping them up to date.

/frontend
╠═ /public
╚═ /src

    volumes:
        // the "contracts" folder does not exist locally however should be copied from the container after
        // mounting the named volume "contracts" in the container.
        - ./frontend/contracts : /usr/src/frontend/contracts 
        - ./frontend/src       : /usr/src/frontend/src
        - ./frontend/public    : /usr/src/frontend/public  
        - contracts            : /usr/src/frontend/contracts

NOTE:
using - ./frontend:/usr/src/frontend does not resolve the issue nor is it a desired solution because i dont want to copy over "node_modules" from the container onto the local machine.

/truffle
╠═ /contracts
╠═ /migrations
╚═ /test

    volumes:
        - ./truffle             : /usr/src/truffle  
        - contracts             : /usr/src/truffle/build

The current outcome is that the named volume "contracts" is bound to both containers correctly and saving a file in the truffle container reflects in the frontend container filesystem however it is not copied over locally through bind mounting to either local folder.

The local truffle folder does create a "build" folder to reflect changes in the container however it is empty even though the containers filesystem does have files in that folder.

The local frontend folder does not create the "contracts" folder which is present in the containers filesystem with files inside, I suspect this is due to bind mounting the actual local truffle folder rather than subfolders from the local frontend folder, regardless neither way copies the files inside their respective folders.

How can you use a named volume to share files between containers which have bind mounted folders to separate folder on the local machine?

  • Where are the files you actually need shared? Do you need a named volume here, or can you bind-mount a host directory there too? Are these files updated as the containers run, or are you just trying to copy build-time content from one place to another? – David Maze Sep 12 '21 at 00:20
  • i've decided to go with bind mounting a folder in the same directory as the two local folders to both containers and accessing that folder from them. The solution is sufficient for me, thanks for pointing out a possible solution! @DavidMaze – marcell-janovszki Sep 15 '21 at 20:11

1 Answers1

0

i've decided to go with bind mounting a folder in the same directory as the two local folders to both containers and accessing that folder from them. The solution is sufficient for me, thanks for pointing out a possible solution! @DavidMaze

example local file structure:
╔═ /frontend
╠═ /truffle
╚═ /contracts

both containers volumes in docker compose:

volumes:
    - ./contracts:/usr/src/frontend|truffle/contracts