Access file of windows machine from docker container

寵の児 提交于 2019-12-08 07:02:28

问题


I have installed Docker Desktop for Windows in Windows 10 operating system. I am running a python script inside docker container which reads file from disk and add few text at the end of files. Now the requirement is to read files from Windows 10 and perform the same operation on it.

Is it possible in docker to read files from OS on top of which Docker is running?


回答1:


Of course, you can use volumes.

For example, you can run the following command:

docker run -v path/to/your/file/on/host:path/to/the/file/on/container your_image



回答2:


The only approach to access the host file is that you can mount the host directory of host system . like if you have

c:\project\test.txt

you can mount c:\project to the docker .

docker run -v c:/project:/src images
By this way you will we able to access the c:project files inside the src folder of the container . or you can create the folder in container and mount it .

And files in container will we accessible to you in /src folder of container and you can do any operation with that file inside the container



来源:https://stackoverflow.com/questions/45267457/access-file-of-windows-machine-from-docker-container

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