On a Mac, how do you mount a volume to a Docker container?
On my linux box, this is easy. All I need to do is something like -v /src/webapp:/opt/webapp
when running the container. But Mac is different since I have to run boot2docker to run a VM in VirtualBox. I've tried running
boot2docker init
boot2docker up
boot2docker ssh # to poke around
boot2docker stop
VBoxManage sharedfolder add "boot2docker-vm" --name "Users" --hostpath /Users
boot2docker up
boot2docker ssh "sudo modprobe vboxsf"
but I get
modprobe: module vboxsf not found in modules.dep
If I ignore that and still try to mount on the VM like so
boot2docker ssh "sudo mkdir /test && sudo mount -t vboxsf Users /test"
I get
mount: mounting Users on /test failed: No such device
I feel like I'm missing something extremely simple, but I can't quite figure it out. Any help would be greatly appreciated.
For folks finding this in the future who want to mount anything other than /Users, there's a script someone made as a gist on github that does the whole process for you and is awesome. Just use this. It saved me a lot of headache of having to keep screwing around with virtualbox. This is tested as of Docker 1.3.0 on my Mac running Yosemite.
EDIT:
Now that docker-machine cli has been deprecated in favor or docker-machine, here's how you can do it with docker-machine:
First, ssh into the docker-machine vm and create the folder we'll be mapping to:
Now share the folder to VirtualBox:
Finally, ssh into the docker-machine again and mount the folder we just shared:
Note: for UID and GID you can basically use whatever integers as long as they're not already taken.
This is tested as of docker-machine 0.4.1 and docker 1.8.3 on OS X El Capitan.
Ok, after digging through a GitHub PR, I was able to figure out a way to do this. For the future readers out there, this process should be fixed in an upcoming release of boot2docker.
This worked for me so I hope it works for others. In the near future, I expect this issue to be solved by boot2docker, especially since the PR from which I got these commands was merged.
EDIT: boot2docker 1.3.0 supports this without any further changes. After updating, I ran these commands: