How do I mount a Docker volume while using a Windows host?
It is possible the /
is interpreted as an option by the CMD Windows shell.
Try first a docker-machine ssh default, in order to open an ssh session in your VM. From there try the docker run again: docker run -v /c/Users/phisch/dev/htdocs:/var/www phisch:dev
As commented by thaJeztah in issue 18290:
You could consider using docker-compose; docker-compose allows you to define bind-mounted volumes relative to the location of the
docker-compose.yml
file.
Using adocker-compose
file allows you to specify all options needed to run your containers in a single file, which makes it ideal for sharing between team members (ie, just rundocker-compose up -d
will start all containers for the project with the right options).
This comment mentions a&dding a second /:
docker run -v //c/Users/phisch/dev/htdocs:`/var/www` phisch:dev
Even in the docker toolbox msys shell session, there are issues (like issue 282)
After lengthy discussion, the issue was that /var/www
had a folder in it.
Mounting /c/Users/phisch/dev/htdoc
onto an empty folder does work, but might not give the expected result, as the default CMD apache2-foreground
might still serve its content based on /var/www
(which would not have htdocs
content if that htdocs
is mounted onto another folder).
If we are talking about Docker on Windows then we have to take in account the fact that all containers are run on VirtualBox.
Before mounting volume to a container we have to be sure that particular folder is available for VirtualBox.
Firstly, to define the name of the current running Docker machine, run
$ docker-machine.exe activedefault
Secondly, add shared folder to VirtualBox:
$ VBoxManage sharedfolder add default --name "some_project" --hostpath D:\Projects\some_project
Thirdly, create the folder
$ docker-machine.exe ssh default 'sudo mkdir --parents /d/projects/some_project'
Fourthly, mount it:
$ docker-machine.exe ssh default 'sudo mount -t vboxsf some_project /d/projects/some_project'
Finally, create a container:
$ docker run -v //d/projects/some_project://d/projects/some_project -d some-image_name
I use Docker for Windows with PowerShell and use $PWD
to refer to the current directory when mounting a volume, and it works well for me. A couple of examples:
docker run -p 2368:2368 -v $PWD/ghost:/var/lib/ghost -d ghostdocker run -p 2368:2368 -v $PWD/:/var/lib/ghost -d ghost