0

I'm trying to share a file from one container to another other. An essential detail is that (the machine running) my docker host does not have explicit access to the file: It pulls a git repo and doesn't know about the internal file organization of the repo (with the single exception of the docker-compose file). Hence, the approach of standard mapping <host-path>:<container-path> is not applicable; e.g. this is not possible for me: How to mount a single file in a volume

Below is the docker-compose file, stripped for increased readability. Say service_1 has the file /app/awesome.txt. We then want to mount it into service_2 as /opt/awesome.txt.

# docker-compose.yml

version: '3'

services:

    service_1:
        volumes:
            - shared_vol:/public
            # how to make service_1 map 'awesome.txt' into /public ?

    service_2:
        volumes:
            - shared_vol/awesome.txt:/opt/awesome.txt

volumes:
    shared_vol:

Working solutions that I have, but are not fond of,

  • running a script/cmd within service_1, copying the file into the shared volume: causes race-condition as service_2 needs the file upon startup
  • introducing a third service, which the other two depends_on, and does nothing but put the file in the shared volume

Any help, tips or guidance is most appreciated!

Wololo
  • 1,249
  • 1
  • 13
  • 25

1 Answers1

1

can you just do something like this

version: '3.5'

volumes:
   xxx:

services:

   service_1:
      ...
      volumes:
         - xxx:/app

   service_2:
      ...
      volumes:
         - xxx:/opt
Ryan.Bartsch
  • 3,698
  • 1
  • 26
  • 52
  • If I can, I will feel extremly stupid: I thought the making of a volume (this way) would overwrite everything within `service_1`'s */app* and `service_2`'s */opt* ... but I will test it regardless and come back: thanks for the suggestion. – Wololo May 18 '20 at 08:00
  • It is absolutely ridiculous how many hours I've spent on this ****, and the proper way to do it was such a trivial approach.. I don't know why I thought the docker host would overwrite anything in the (shared) volume, but obviously it doesn't... Well thank you good sir, you made my week! – Wololo May 18 '20 at 08:28