- 1 year ago
How to map a local drive in a windows docker container with net use?
To map a local drive in a Windows Docker container with net use
, you can use the -v
option when running the docker run
command to mount the local drive as a volume inside the container. Then you can use the net use
command inside the container to map the mounted volume to a drive letter. Here are the steps:
Run the
docker run
command with the-v
option to mount the local drive as a volume inside the container. For example, to mount theC:\data
folder on the host machine as a volume nameddata
inside the container, run:kotlindocker run -it -v C:\data:data microsoft/windowsservercore cmd
Inside the container, use the
net use
command to map the mounted volume to a drive letter. For example, to map thedata
volume to theZ:
drive, run:kotlinnet use Z: \\localhost\data
Note that you may need to run this command with administrative privileges in order to map the drive successfully.
Verify that the drive has been mapped by running the
net use
command without any arguments. This should list all currently mapped drives, including the one you just mapped.
That's it! You should now be able to access the local drive on the host machine from within the container using the mapped drive letter.