Having Docker access External files

青春壹個敷衍的年華 提交于 2020-01-09 07:48:21

问题


I am interested in having docker have access to external files, however, I do not wish to include them as a volume. The files that I need access to will change over time, and this means I would need to re-mount repeatedly.

Unless, I can mount a mere directory, and whatever is in that directory is also mounted.

I am just in need of allowing a software program pushed into a container, to run "over" my local system, where this software program has access to files on my local system.

Advice? Is there another way besides adding the files needing to be processed as a volume?


回答1:


I solved the same problem with below commands

docker run  --mount type=bind,source="$(pwd)"/data,target=/home/data -it <name_of_container>

Note "-it conainter_name" should be the last flags.




回答2:


It sounds like mounting a host directory in the container is what you're looking for. You won't have to restart the container to pick up changes to the mounted directory. Link to relevant docs.




回答3:


I wonder if the ADD command could help you accomplish your goal. For instance, given the Dockerfile line:

ADD /Users/userX/myappfiles /appfiles

and the command line:

docker run myapp --input /myappfiles

myapp would be able to access /Users/userX/myappfiles on the local filesystem to fetch its inputs.



来源:https://stackoverflow.com/questions/30652299/having-docker-access-external-files

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