Docker Community Forums

Share and learn in the Docker community.

Volume mounts in windows does not work


(Hwyss) #163

For me, all the approaches described in this thread did not work. What did help was described here: https://stackoverflow.com/questions/42203488/settings-to-windows-firewall-to-allow-docker-for-windows-to-share-drive/43904051#43904051

In a nutshell: ensure that the DockerNAT is classified as a private network. Powershell command:

Set-NetConnectionProfile -interfacealias "vEthernet (DockerNAT)" -NetworkCategory Private

Background: since I’m in a corporate setting, I have no control over the firewall - and smb services are only accessible from private or domain networks, but not from public networks.

Hope that helps someone.


(Piotrwolski) #164

Looks like this some people still struggle to find a solution, even with all the above suggestions.

I’ve had a problem with this functionality as well, and after trying a number of fixes suggested here, I’ve discovered another aspect of this, that might help some.

Mounting drivers in Linux is a non-trivial operation and, following my observation, looks that it’s also asynchronous.

In my case, I was testing mounting functionality by issuing:

docker run -it -v "$PWD":/usr/src/app -w /usr/src/app node:8.9-alpine ls -l

But the output was empty, although my host’s working directory wasn’t. I wanted to check that the -w switch (set working directory on guest) works correctly so I’ve changed the command to:

docker run -it -v "$PWD":/usr/src/app -w /usr/src/app node:8.9-alpine pwd & ls -l

which has not only returned the right path, but also listed all the contents of my hosts working directory.

This suggested to my that my previous command failed to list the contents, simply because the drive was not mounted at the point of execution.

After making that observation, I’ve started adding “sleep 1s &” before the main command to pause the execution before the guest OS mounts the drive. This solved all my problems with mounting.

I know it’s not the nicest fix and it feels hacky, but at the end of the day, lets not forget that this command builds a virtual operating system - an operation which is very complex and, as it turns up, rather hard to predict, unless you’re willing to learn the ins-and-outs of the guest OS.


(Aderderian) #165

WIndows 10, Docker for windows with linux containers not working…come on. What are the alternatives if I am developing a solution in Visual Studio and planning on pushing out a .net core app out to AKS in Azure? This seems like a huge problem.


(Ailjushkin) #166

FYI:
I have two drives: C and D. The drive D is sharing fine what I cannot say about the C drive - after applying changes the checkbox of this drive is constantly checking out.

I had to restart the docker daemon to be able to turn on all shared drives so be informed about this strange behaviour.


(Proskeh) #167

If you have trouble getting this to work on Windows 10 and Linux containers, try unchecking and checking the shared drive again. Also make sure to use the format suggested in the hint below the shared drives (I used uppercase C instead of lowercase c which was probably partly the reason for my issues). Also I’m not sure how well this works with your password being changed, so unchecking and checking the drive again prompts you for your (possibly new) password.

Hope this helps :slight_smile:


(Modenaf360) #168

On Windows (10), DOCKER appears to be running on Hyper-V. like VM mount.
So, architecture docker server is on running VM BOX. The default volume mount setting is c / Users. You can add this in the Oracle VM VertualBox> setting> shared folder. Or C:\Users[realuser].docker\machine\machines\default\default\default.vbox.

  <SharedFolders>
    <SharedFolder name="c/Users" hostPath="\\?\c:\Users" writable="true" autoMount="true"/>
	<SharedFolder name="f/dockerVolume" hostPath="\\?\f:\dockerVolume" writable="true" autoMount="true"/> <!--this is addition-->
  </SharedFolders>

You can add docker container expose volume mount to VM mount. if you change vm mount, restart ‘defult’ VM in the Oracle VM VirtualBox or Restart

Windows (mount_here)<----> Virtual Box (mount_here)<—> CoreOS(mount_here)

And I found this, if use Kitematic, only can use Users folder.


(Harveydobson) #169

Hi All,

I have been trying to work this out on and off over the last few days, and have finally cracked it with some help from Kitematic - for myself at least. I am using docker-compose, but I imagine it should be the same.

First thing is, as mentioned > 1,000,000 times above, tick the shared drive box in the main docker for windows application.

Next, simply use /host_mnt/

/host_mnt/<windows_drive>/<your_dir>

i.e. in my case

/host_mnt/c/xampp/htdocs/

I tried a variety of methods, it’s been quite confusing as I’ve been using Docker alongside Linux Subsystem for Windows, so initially I was referencing directories off of the linux box, but this is incorrect as even when running docker from the sub-system, it is only running as a client, so everything is relevant to the docker installation on the windows machine itself.

Here is my full docker-compose markup for better perspective:

version: '2'

services:
   db:
     build: ./mysql
     volumes:
       - db_data:/var/lib/mysql
     environment:
       MYSQL_ROOT_PASSWORD: root
   php:
    build: ./php
    ports:
      - '80:80'
    restart: always
    volumes:
       - /host_mnt/c/xampp/logs/:/var/log/apache2/
       - /host_mnt/c/xampp/htdocs/:/var/www/html/
    depends_on:
      - db
volumes:
    db_data:

Hope this helps someone!


(Ganni) #170

Hi! I just got it to work on Windows 10 without changing any security settings.
Hope it helps somebody! :blush:

docker run -v /User/Documents/directory-to-share-on-host:/dir-on-container image/name ls

it’s really strange as if there is some kind of link or shortcut defined for path for current user. I don’t know why but it works just like that!

Just drop the /c/Users/username and replace it with /User/
/c/Users/username/directories -> /User/directories


Docker toolbox and windows paths
(Pdavis68) #171

I cannot get docker to get access to host directories at all. Any time I try to do it, it creates a series of directories in the docker moby machine…

If I run:docker run --rm -v /:/data alpine ls -al /data

I get:

total 8
drwxr-xr-x   16 1001     50             400 Oct 13 14:45 .
drwxr-xr-x   25 root     root          4096 Oct 13 14:48 ..
drwxr-xr-x    2 root     root          1420 Oct 13 07:47 bin
drwxrwxr-x   14 root     50            4380 Oct 13 12:47 dev
drwxr-xr-x   11 root     root          1080 Oct 13 12:48 etc
drwxrwxr-x    4 root     50              80 Oct 13 12:47 home
-rwxr-xr-x    1 root     root           496 Jul 19 18:33 init
drwxr-xr-x    5 root     root           860 Oct 13 07:47 lib
lrwxrwxrwx    1 root     root             3 Oct 13 07:47 lib64 -> lib
lrwxrwxrwx    1 root     root            11 Oct 13 07:47 linuxrc -> bin/busybox
drwxr-xr-x    5 root     root           100 Oct 13 12:47 mnt
drwxr-xr-x    2 root     root           180 Oct 13 07:47 opt
dr-xr-xr-x  115 root     root             0 Oct 13 07:46 proc
drwxrwxr-x    2 root     50              80 Oct 13 07:47 root
drwxrwxr-x    5 root     50             100 Oct 13 12:47 run
drwxr-xr-x    2 root     root          1420 Oct 13 07:47 sbin
dr-xr-xr-x   13 root     root             0 Oct 13 07:47 sys
lrwxrwxrwx    1 root     root            13 Oct 13 12:47 tmp -> /mnt/sda1/tmp
drwxr-xr-x    7 root     root           140 Oct 13 07:47 usr
drwxrwxr-x    8 root     50             180 Oct 13 07:47 var

If I try: docker run --rm -v //f/temp:/data alpine ls -al /data (I run docker on my F: drive)

It creates the path /f/temp in the moby machine.

I have the F: drive shared in docker for windows settings.

I can’t understand why this is so difficult to get working. I would think this would be pretty basic functionality.


(Karlroberts) #172

You need to swap all the back slashes to forward slashes
so change

docker -v C:\my\folder:/mountlocation …

to

docker -v C:/my/folder:/mountlocation

I normally call docker from a cmd script in that script I do this…

SETLOCAL

REM capture the path to this file so we can call on relative scrips without having to be in this dir to do it.
set mypath=%~dp0

REM strip last char
set PREFIXPATH=%mypath:~0,-1%

echo "PREFIXPATH=%PREFIXPATH%"

mkdir -p %PREFIXPATH%\my\folder\to\mount

REM swap \ for / in the path because docker likes it that way in volume mounting
set PPATH=%PREFIXPATH:\=/%

echo "PPATH=%PPATH%"

REM pass all args to this script to the docker command line with %*

docker run --name mycontainername --rm -v %PPATH%/reports:/output  myimage %*

ENDLOCAL

(Silentbang) #173

Changing Local Security Policy works for me, as I couldn’t set the password without special character due to the company policy. Thanks @stevenwillett & @ijeweb.


(Ipereto) #174

Thank you so much! It works!


(Tylim) #175

thank man, double slash work. I have been stuck for days, your method work!!


#176

This is brilliant, and solved my issues. Should be moved to the top of the que!


#177

I take that back. All this is doing is running bash on the host machine after it closes out of docker.
I still can’t make it work short of using docker cp to copy the files over


#178

FYI, my problem turned out to be that when you change your windows password the docker settings must be reset.
I had changed my windows password recently, so even while the setting showed the drive as shared the permissions to it were incorrect. In docker settings, Unshare, then click again to reshare then ensure your credentials are correct.
see https://rominirani.com/docker-on-windows-mounting-host-directories-d96f3f056a2c