我想在我的工作过程中使用泊坞窗图像。 例如,我想使用larryprice / sass将我的SASS文件编译为CSS。 这张图很简单:
FROM ruby:2.2 RUN gem install sass WORKDIR /tmp ENTRYPOINT ["sass", "--watch", "/src"]我使用的是Windows 10,Docker 1.11和VirtualBox 5.0.16。
我的项目文件放在工作SSD上,映射到逻辑驱动器D - D:\ Projects \ Foo \ Bar \ web \ sass
所以,我的问题如下:当我从驱动器D附加一个卷到容器时:(通过$ PWD或MINGW样式的完整路径/ D / Projects / Foo / Bar / web / sass),例如
cd /D/Projects/Foo/Bar/web docker run --name sass -v $PWD/sass:/src --rm larryprice/sass容器看不到任何SASS文件:
$ docker exec -i -t sass /bin/bash root@541aabac9ceb:/tmp# ls -al /src/ total 4 drwxr-xr-x 2 root root 40 May 3 13:05 . drwxr-xr-x 50 root root 4096 May 3 13:05 ..但是,当我从系统磁盘(C :)安装卷时,一切正常:
$ docker run --name sass -v ~/sass:/src --rm larryprice/sass [Listen warning]: Listen will be polling for changes. Learn more at https://github.com/guard/listen#polling-fallback. >>> Sass is watching for changes. Press Ctrl-C to stop. >>> New template detected: ../src/test.sass write /src/test.css write /src/test.css.map如何从Windows中需要的任何地方安装卷? 或者在我的情况下我做错了什么?
ps在路径中添加前导斜杠也不起作用:
docker run --name sass -v //d/Projects/Foo/Bar/web/sass:/src --rm larryprice/sassI want to use a docker image in my work process. For example I want to use larryprice/sass to compile my SASS files to CSS. This image is pretty simple:
FROM ruby:2.2 RUN gem install sass WORKDIR /tmp ENTRYPOINT ["sass", "--watch", "/src"]I'm using Windows 10, Docker 1.11 and VirtualBox 5.0.16.
My project files placed on work SSD, that mapped to logical drive D - D:\Projects\Foo\Bar\web\sass
So, my problem is following: when I attach a volume to the container from drive D: (by $PWD or by full path in MINGW style /D/Projects/Foo/Bar/web/sass) e.g.
cd /D/Projects/Foo/Bar/web docker run --name sass -v $PWD/sass:/src --rm larryprice/sassthe container can't see any SASS files:
$ docker exec -i -t sass /bin/bash root@541aabac9ceb:/tmp# ls -al /src/ total 4 drwxr-xr-x 2 root root 40 May 3 13:05 . drwxr-xr-x 50 root root 4096 May 3 13:05 ..But when I mount a volume from system disk (C:) all works fine:
$ docker run --name sass -v ~/sass:/src --rm larryprice/sass [Listen warning]: Listen will be polling for changes. Learn more at https://github.com/guard/listen#polling-fallback. >>> Sass is watching for changes. Press Ctrl-C to stop. >>> New template detected: ../src/test.sass write /src/test.css write /src/test.css.mapHow I can mount volumes from any place I need in Windows? Or what I'm doing wrong in my case?
p.s. Add leading slash to the path also not working:
docker run --name sass -v //d/Projects/Foo/Bar/web/sass:/src --rm larryprice/sass最满意答案
好的。 最后,我找到了自己问题的解释和解决方案。 此解决方案适用于Windows和MacOS X(因为它们都使用VirtualBox使Docker完成任务)。
问题的根源包括两点:
默认情况下,VirtualBox VM对主机文件系统的访问权限有限( 证明 )。 在我的情况下,它可以访问驱动器C上的用户文件夹:通过VBox共享文件夹( 屏幕 )。 感谢这一点,我可以使用像这样的卷映射:〜/ sass:/ src(或完整路径:/ c / users / dbykadorov / sass)。 不幸的是,这个配置不允许我使用/ c / users /之外的任何路径。解决此问题的方法:将另一个共享文件夹添加到VM,指向我需要的目录。 我创建了新的共享d:/ Projects( 屏幕 )。 重新启动VM。
我希望你能完成你的案子。 但在我的情况下,VirtualBox不会在系统启动时挂载新的共享文件夹。 所以,我遇到了第二个问题:
VirualBox没有安装我刚添加的其他共享文件夹。附加解决方案
让我们尝试手动挂载共享文件夹。 通过任何可用方式登录VM。 在控制台中:
# Create mount point directory $ mkdir -p /d/Projects # Mount shared folder $ mount -t vboxsf d/Projects /d/Projects好的,这就是诀窍! 现在我可以挂载任何项目的目录(在D:\ Projects中)!
但是......当我重新启动我的VM时,mountpoint将消失=(现在我们需要使我们的挂载点更持久。如下所述:
# Make a file bootlocal.sh $ touch /var/lib/boot2docker/bootlocal.sh # Edit it $ vi /var/lib/boot2docker/bootlocal.sh # Add follovin lines here: #!/bin/sh mkdir -p /d/Projects mount -t vboxsf d/Projects /d/Projects # Save the file and reboot VM重要说明 :要使卷创建更清晰,最好将共享文件夹挂载到与主机上相同的路径。 例如,如果我们需要从E:\ Foo \ Bar \ Baz(MINGW风格的/ e / Foo / Bar / Baz)创建卷,那么我们需要为E:\ Foo \ Bar \ Baz添加新的共享文件夹并准确安装它到你的Docker VM中的/ e / Foo / Bar / Baz。
就这些。
Okay. Finally I found an explanation and solution for my own question. This solution will work for both Windows and MacOS X (because both of them uses VirtualBox to make Docker do the things).
The source of the problem consists from two points:
By default, VirtualBox VM have limited access to the host filesystem (proof). In my case it have access to the users folder on drive C: via VBox shared folder (screen). Thank to this, I can use volumes mapping like this one: ~/sass:/src (or full path: /c/users/dbykadorov/sass). Unfortunately, this configuration not allows me to use any path outside from /c/users/.Solution for this point: add another shared folder to the VM, pointed on directory I need. I created new share d:/Projects (screen). Reboot your VM.
I hope here you'll complete your case. But in my case, VirtualBox does not mount new shared folder at system startup. So, I got second problem:
VirualBox does not mount additional shared folder, that I just added.Additional solution:
Let's try to mount shared folder manually. Log into VM by any available ways. In console:
# Create mount point directory $ mkdir -p /d/Projects # Mount shared folder $ mount -t vboxsf d/Projects /d/ProjectsOkay, this do the trick! Now I can mount any project's directory (within D:\Projects)!
But... when I'll reboot my VM the mountpoint will disappear =( Now we need to make our mount point more persistent. As described here:
# Make a file bootlocal.sh $ touch /var/lib/boot2docker/bootlocal.sh # Edit it $ vi /var/lib/boot2docker/bootlocal.sh # Add follovin lines here: #!/bin/sh mkdir -p /d/Projects mount -t vboxsf d/Projects /d/Projects # Save the file and reboot VMImportant note: to make volumes creating more clear it will be good idea to mount shared folder to the same path as on the host. E.g. if we need to create volumes from E:\Foo\Bar\Baz (/e/Foo/Bar/Baz in MINGW style) then we need to add new shared folder for E:\Foo\Bar\Baz and mount it exactly to /e/Foo/Bar/Baz in your Docker VM.
That is All.
更多推荐
发布评论