问题
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