Dockerized executable read/write on host filesystem

一笑奈何 提交于 2019-12-11 14:32:54

问题


I just dockerized an executable that reads from a file and creates a new file in the very directory that file came from.

I want to use Docker in that setup, so that I avoid installing numerous third-party libraries in the production environment.

My problem now: I have file /this/is/a.file on my underlying (host) file system and my executable is supposed to create /this/is/b.file.

As far as I see it, the only chance to get this done is by mapping a volume that points to /this/is and then let the executable know where I mounted it to in the docker, container.

Am I right? Or is there a way that I just pass docker run mydockerizedstuff /this/is/a.file without using Docker volumes?


回答1:


You're correct, you need to pass in /this/is as a volume and the executable will write to that location.

If you want to constrain the thing even more, you can pass /this/is/b.file as a volume. You need to create it (simply via touch) beforehand, otherwise Docker will consider it a directory and create it as such for you, but you'll know that the thing won't be able to create /this/is/c.file or any other thing.



来源:https://stackoverflow.com/questions/48685327/dockerized-executable-read-write-on-host-filesystem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!