I 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) eg
cd /D/Projects/Foo/Bar/web
docker run --name sass -v $PWD/sass:/src --rm larryprice/sass
the 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.map
How I can mount volumes from any place I need in Windows? Or what I'm doing wrong in my case?
ps Add leading slash to the path also not working:
docker run --name sass -v //d/Projects/Foo/Bar/web/sass:/src --rm larryprice/sass
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:
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:
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/Projects
Okay, 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 VM
Important note : to make volumes creating more clear it will be good idea to mount shared folder to the same path as on the host. Eg 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.