Can't mount Windows host directory to Docker container

两盒软妹~` 提交于 2020-01-13 19:46:07

问题


I'm on Windows 10 Pro with Docker Version 1.12.0-rc3-beta18 (build: 5226). I would like use Docker for PHP development on Windows machine. I tried all possible (I hope) variations of mounting host directory into Docker container:

  • //c/Users/...
  • /c/Users/...
  • //C/Users/...
  • /c/Users/...
  • c:/Users/...
  • c:\Users...
  • "c:\Users..." Neither of variants launch container. Yes, docker run creates container and I can see it with docker ps --all. But I can't it start. E.g. I tried simple documentation example:

docker run -d -P -v "C:\temp":/opt/webapp training/webapp python app.py

and

docker logs e030ba0f7807

replays as

python: can't open file 'app.py': [Errno 2] No such file or directory

What happened?


回答1:


If you are using docker with docker-machine, you would need to register c:\temp first as a shared folder in VirtualBox.

See "docker with shared folder d drive"

From within a docker-machine ssh session:

sudo touch /mnt/sda1/var/lib/boot2docker/bootlocal.sh

Add to that file:

mkdir -p /mnt/temp
mount -t vboxsf -o defaults,uid=`id -u docker`,gid=`id -g docker` temp /mnt/temp

That path would then be accessible through /mnt/temp for instance.

The same applies for C:\Users, which is already a shared folder c/Users.

It is accessible with /c/Users.


With Hyper-V, see "Running Docker on Hyper-V" from Henning M Stephansen:

Hyper-V is a more isolated and restrictive environment than VMWare or VirtualBox is, so there’s no concept of shared folders.
However we can mount and access Windows shares from our Docker VM.

The first thing you need to do is to share a folder. This folder can be restricted to just your user.
If the VM has access to the network through an External Virtual Switch or an Internal Virtual Switch you should be able to mount your folder from the docker VM.

To be able to mount a windows share from Boot2Docker/Tiny Core Linux we need to install some additional module (This might be included in your image):

wget http://distro.ibiblio.org/tinycorelinux/5.x/x86/tcz/cifs-utils.tcz
tce-load -i cifs-utils.tcz

Now we can mount the shared folder using the following command

sudo mount -t cifs //HOST-IP-HERE/SharedFolderPath /path/where/we/want/it/mounted -o username=HOST_USERNAME_HERE


来源:https://stackoverflow.com/questions/38261392/cant-mount-windows-host-directory-to-docker-container

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