Using Docker with -v "c:mydir:/mydir" or with -v "c:/mydir:/mydir" correctly mounts the directory C:mydir inside my container.
However, I once omitted the drive letter by mistake and did something like:
docker run -it –rm -v "/mydir:/mydir" bash
The files saved to /mydir inside the container didn’t appear in the Windows directory C:mydir. They reappear inside other Docker containers if I again mount "/mydir" without the drive letter. I cannot find these files anywhere on my hard drive.
So exactly which Windows directory got mounted inside the container when I omitted the drive letter in the example above?
Thanks…
2
Answers
First off, I didn’t realize this "feature" existed. You probably also saw that the docs say,
I was able to confirm that on Linux using
docker run --rm -it -v /foo:/foo ...
does actually create/foo
which is … surprising and potentially disastrous. (This is another reason to be selective about which users can run Docker commands and how.)Anyways, I tried the same thing on Windows 10 using Git Bash and, I’m guessing because I wasn’t running the command as an administrator or a privileged user, docker complains that access is denied when it attempts to create the directory at
C:Program FilesGitfoo
.However, if you’re not using Git Bash, that may not directly answer your question but should be something to go on. I’d expect the newly directory to be somewhere within Program Files (e.g. powershell).
UPDATE:
After some more digging and trying myself using PowerShell, I’ve determined that the files actually live within the Docker VM that Windows uses.
I was able to start a new container (using the nsenter1 image) which pokes into this VM and find the files using the following:
And, in my case, the files were located (again, in the VM via the container) at /containers/services/01-docker/rootfs/foo
See this forum post for more details.
Docker volumes on Windows are always created in the path of the graph driver, which is where Docker stores all image layers, writeable container layers and volumes. By default the root of the graph driver in Windows is
but you can mount a volume to a specific directory when you run a container. You can copy paste the above path in windows explorer & check it out.
However, if you want to mount C:mydir inside the docker container than you could do it either by,
or
Alternaively, you could also go to the directory(in this case C:mydir) & try,
For more info, you can read the official documentation here.