无法将Windows主机目录挂载到Docker容器 [英] Can't mount Windows host directory to Docker container
问题描述
- // 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中的共享文件夹。
从 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>
为了能够从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 withdocker 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屋!