Rakesh K
Rakesh K

Reputation: 712

Access file of windows machine from docker container

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?

Upvotes: 9

Views: 17112

Answers (2)

Himanshu sharma
Himanshu sharma

Reputation: 7929

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

Upvotes: 5

D. Gonçalves
D. Gonçalves

Reputation: 719

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

Upvotes: 7

Related Questions