How do I mount a Docker volume while using a Windows host?

无人久伴 提交于 2019-11-28 08:44:18

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 a docker-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 run docker-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).

Oleksandr Petrenko

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  active
default

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
Johnny Oshika

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 ghost

docker run -p 2368:2368 -v $PWD/:/var/lib/ghost -d ghost
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!