无法将Windows主机目录挂载到Docker容器 [英] Can't mount Windows host directory to Docker container

查看:800
本文介绍了无法将Windows主机目录挂载到Docker容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows 10 Pro与Docker版本1.12.0-rc3-beta18(构建:5226)。我想在Windows机器上使用Docker进行PHP开发。我尝试将主机目录安装到Docker容器中的所有可能(希望)变体:




  • // c / Users /...

  • / c / Users /...

  • // C / Users /...

  • / c / users /...

  • c:/ Users /...

  • c:\Users ...

  • c:\Users ...
    两个变体都不会启动容器。是的, docker运行创建容器,我可以看到它与 docker ps --all 。但我不能开始。例如。我尝试了简单的文档示例:



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





docker日志e030ba0f7807



重播为



python:无法打开文件'app.py':[Errno 2]没有这样的文件或目录



发生了什么

解决方案

如果您使用docker与docker-machine,您需要注册 c: \\temp 首先作为VirtualBox中的共享文件夹。



请参见具有共享文件夹d驱动器的docker



docker-machine ssh 会话:

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

添加到该文件:

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

路径然后可以通过 / mnt / temp 来访问。



同样适用于 C:\Users ,它已经是共享文件夹 c / Users



可以通过 / c / Users 访问。






使用Hyper-V,请参阅 Running Docker来自 Henning M Stephansen 的Hyper-V :


Hyper-V是比VMWare或VirtualBox更环保的环境,所以没有共享文件夹的概念。

但是我们可以挂载和访问Windows我们的Docker VM共享。



您需要做的第一件事是共享一个文件夹。该文件夹可以仅限于您的用户。

如果VM可以通过外部虚拟交换机或内部虚拟交换机访问网络,则应该能够从Docker VM安装文件夹。 p>

< img src =https://i.stack.imgur.com/gCWFb.jpgalt =http://www.henning.ms/wp-content/uploads/2015/05/share-internet.jpg>


为了能够从Boot2Docker / Tiny Core Linux安装Windows共享,我们需要安装一些额外的模块(这可能包含在您的图像中):




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




现在我们可以使用以下命令挂载共享文件夹



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


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?

解决方案

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

这篇关于无法将Windows主机目录挂载到Docker容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆