无法在Windows 10上使用Docker Toolbox共享/挂载卷 [英] Unable to share/mount Volume with Docker Toolbox on Windows 10

查看:187
本文介绍了无法在Windows 10上使用Docker Toolbox共享/挂载卷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用docker设置我的项目。我正在Windows 10 Home上使用Docker Toolbox。我是Docker的新手。据我了解,我必须将文件复制到新容器中并添加一个卷,以便我可以持久保存gulp所做的更改。

I am trying to setup my project with docker. I am using Docker Toolbox on Windows 10 Home. I am very new to docker. To my understanding I have to copy my files to new container and add a volume so that I can persist changes made by gulp.

这是我的文件夹结构

-- src
|- dist
|- node-modules
|- gulpfile.js
|- package.json
|- Dockerfile

Dockerfile代码

The Dockerfile code

FROM node:8.9.4-alpine
RUN npm install -g gulp
CMD [ "ls", 'source' ]

我为 * docker run -v *

例如

docker run -v /$(pwd):/source <container image>
docker run -v //c/Users/PcUser/Desktop/proj:/source <container image>
docker run -v //c/Users/PcUser/Desktop/proj:/source <container image>
docker run -v //d/proj:/source <container image>
docker run -v /d/proj:/source <container image>

*但没有运气*

谁能描述您将如何使用相同的结构为自己设置它。以及为什么我无法挂载主机文件夹。

Can anyone describe how would you set it up for yourself with the same structure. And why am I not able to mount my host folder.

PS:如果我使用两个容器,一个用gulp编译我的代码,另一个用nginx来编译我的代码的内容 dist 文件夹。我该怎么办。

P.S: If I use two containers one for compiling my code with gulp and one with nginx to serve the content of dist folder. How will I do that.

推荐答案

@ sxm1972感谢您的努力和帮助。

@sxm1972 Thank you for your effort and help.

您可能正在使用Windows Pro或服务器版本。我正在使用 Windows 10家庭版

You are probably using Windows Pro or a server edition. I am using Windows 10 Home edition

这是我解决的方法,因此其他使用相同设置的人可以解决他们的问题。

Here is how I solved it, so other people using same setup can solve their issue.


解决这个问题的方法可能更好,如果有效率的话请发表评论。

There may be a better way to solve this, please comment if there is an efficient way.

所以...

首先,问题...为什么我看不到来自

First, the question... Why I don't see my shared volume from PC in my container.

答案:如果我们将Docker的Boot2Docker与VirtualBox一起使用(我是),那么无论何时装入卷,它都指向内部的文件夹 Boot2Docker VM

Ans: If we use docker's Boot2Docker with VirtualBox (which I am) then whenever a volume is mounted it refers to a folder inside the Boot2Docker VM

图片:-v在VirtualBox Boot2Docker中使用docker的结果

因此,如果我们尝试使用 $ ls 它将显示一个空文件夹,在我的情况下确实如此。

So with this if we try to use $ ls it will show an empty folder which in my case it did.

因此,如果我们将文件夹实际安装到 Boot2Docker VM 希望将我们的文件从Windows环境共享到Container。

So we have to actually mount the folder to Boot2Docker VM if we want to share our files from Windows environment to Container.

图片:结果挂载窗口<-> Boot2 Docker<->容器

要实现此目的,我们必须使用以下命令

To achieve this we have to manually mount the folder to VM with the following command

vboxmanage sharedfolder add default --name "<folder_name_on_vm>" --hostpath "<path_to_folder_on_windows>" --automount

如果您在运行命令时出错,则说找不到vboxmanager将虚拟文件夹文件夹路径添加到系统路径。对我来说是 C:\程序文件\Oracle\VirtualBox

运行命令后,您将在 root 上看到< folder_name_on_vm> 。您可以通过 docker-machine ssh默认值进行检查,然后通过 ls / 进行检查。确认文件夹< folder_name_on_vm> 存在之后,您可以将其用作容器的卷。

After running the command, you'll see <folder_name_on_vm> on root. You can check it by docker-machine ssh default and then ls /. After confirming that the folder <folder_name_on_vm> exist, you can use it as volume to your container.

docker run -it -v /< folder_name_on_vm>:/ source< container> sh

希望这会有所帮助...!

Hope this helps...!

PS如果您感觉到懒惰并且不需要挂载文件夹,您可以将项目放置在 C:/ Users 文件夹中,因为默认情况下该文件夹已挂载在VM上图像

P.S If you are feeling lazy and don't wan't to mount a folder, you can place your project inside your C:/Users folder as it is mounted by default on the VM as show in the image.

这篇关于无法在Windows 10上使用Docker Toolbox共享/挂载卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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