I'm trying to mount a directory as a data volume on OS X using docker machine with -v.
I tried to follow this post https://github.com/boot2docker/boot2docker/issues/678#issuecomment-98066644 but it didn't work.
I saw on the doc it says docker daemon has limited access to OS X, but is there any walkaround I can do? Thank you!
You should be able to add a shared folder from the VirtualBox UI and it should be recognized. Can you try that?
Which directory are you trying to mount? If it's within /Users
an argument like -v /Users/foo/webapp:/code
should "just work" with VirtualBox shared folders. If it's outside of /Users
you will need to manually create and mount the share.
Can we get a docker-machine
command to be able to do this? I tried using a symlink in /Users/<my-user>
directory but that didn't work
:+1: This would be a big quality of life improvement over having to interface directly with the Virtualbox UI.
Shared folders are definitely exposed through the Virtualbox API; and I remember vagrant handling it quite easily.
@ehazlett
You should be able to add a shared folder from the VirtualBox UI and it should be recognized. Can you try that?
Tried to add it through the UI, or using CLI as described below.
@nathanleclaire says:
If it's outside of /Users you will need to manually create and mount the share.
Here too trying to mount non-/Users
folders, but I see nothing. I did:
$ VBoxManage sharedfolder add default --name /stuffs --hostpath /DEVEL/stuffs/ --automount
$ docker run -it -v /DEVEL/stuffs:/stuffs ubuntu bash
The stuffs
folder looks empty in the VM.
@huguesfontenelle Its exposed but still need to be mounted with mount command. i am gonna raise issue to deal with it in more sustainable manner
@jas99 thanks. What would that command be? On the host machine or within the VM?
@huguesfontenelle
if using boot2docker
create file bootlocal.sh inside /var/lib/boot2docker; so it will persist and get executing when boot2docker images runs
mkdir [target folder]
sudo mount -t vboxsf -o uid=1000,gid=1000 [hostfolder] [target folder]
@jas99 your answer looks like https://github.com/boot2docker/boot2docker/issues/813 or http://stackoverflow.com/questions/23439126/how-to-mount-host-directory-in-docker-container/27320731#27320731
However I did not specifically install boot2docker. I'm using the latest Docker Toolbox. (I assume that OP does also, given the date of the post shortly after this 1.8.2 release).
I'll try to fill this as a proper bug report.
$ docker version
Client:
Version: 1.8.2
API version: 1.20
Go version: go1.4.2
Git commit: 0a8c2e3
Built: Thu Sep 10 19:10:10 UTC 2015
OS/Arch: darwin/amd64
Server:
Version: 1.8.2
API version: 1.20
Go version: go1.4.2
Git commit: 0a8c2e3
Built: Thu Sep 10 19:10:10 UTC 2015
OS/Arch: linux/amd64
$ docker info
Containers: 32
Images: 26
Storage Driver: aufs
Root Dir: /mnt/sda1/var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 90
Dirperm1 Supported: true
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 4.0.9-boot2docker
Operating System: Boot2Docker 1.8.2 (TCL 6.4); master : aba6192 - Thu Sep 10 20:58:17 UTC 2015
CPUs: 1
Total Memory: 1.956 GiB
Name: default
ID: ZNKJ:54GP:Z3OQ:2U4L:CB6B:BO3V:YS2U:AT2X:ARMA:WBM5:ID4J:SXWP
Debug mode (server): true
File Descriptors: 12
Goroutines: 17
System Time: 2015-09-29T12:21:41.763009305Z
EventsListeners: 0
Init SHA1:
Init Path: /usr/local/bin/docker
Docker Root Dir: /mnt/sda1/var/lib/docker
Labels:
provider=virtualbox
huguesfo@pcus392 /DEVEL/genevar/vcpipe/docker
$ uname -a
Darwin pcus392.uio.no 13.4.0 Darwin Kernel Version 13.4.0: Wed Mar 18 16:20:14 PDT 2015; root:xnu-2422.115.14~1/RELEASE_X86_64 x86_64
$ VBoxManage sharedfolder add default --name /src --hostpath /path/to/src --automount
$ docker run -it -v /Users/$USER:/home -v /path/to/src:/src ubuntu bash
# mount -t vboxsf -o uid=1000,gid=1000 /src /src
/home
is properly mounted.
/src
is not.
The latest mount command results in mount: Protocol error
.
Trying # mount --bind -t vboxsf -o uid=1000,gid=1000 /src /src
instead is silent but results in empty /src
folder.
I think the problem here (correct me if otherwise) is that boot2docker has no VBox Guest Additions, so you can't mount using vboxsf protocol. /Users
sharing is hard-coded in somehow (NFS?), but no other folders. Potentially, the only ways around this are (i) for VBoxGuestAdditions to be made available for boot2docker, or (ii) for docker-machine to have an option that when VBoxGuestAdditions is required, it uses an alternative goes OS that supports it, such as Ubuntu.
@grahampugh boot2docker ISO does have Guest Additions installed. That's how the /Users
mount is done by default.
Hi, thanks, that's interesting. I wonder why a vagrant VM has no problem mounting folders outside /Users, e.g. /Volumes/my-external-disk, but boot2docker can't.
I just found the reason for this issue.
See this script of boot2docker
https://github.com/boot2docker/boot2docker/blob/master/rootfs/rootfs/etc/rc.d/vbox#L37
A working workaround is this docker image - but that is really dirty as it runs in privileged mode
https://hub.docker.com/r/jrotter/boot2docker-automounter/
Hi All,
I want to mount container (docker image) directory to local machine data volume so that I can modify files outside the container using docker-machine. Can anyone please help me on this.
FYI: I am able to mount my local machine data volume to container.
This (see L62 and L103) is the approach I took to getting my /Volumes dir mounted in the docker machine image, and also handling port forwarding, ntp, and a number of other issues I've encountered while running docker on OSX.
The wrapper script shuts down the machine if there are changes to be made, makes the changes, then restarts the machine. So, instead of docker-machine start default
, I just execute this script.
Closing. Duplicate of #13
The method recommended by @jas99 worked for me.
This whole thing took me a while to figure out so I made a script that automates the process based on different comments on this thread : https://gist.github.com/ghugues/8988d0fbc63ed0929b05d951c832e02e
Take a look at 0.9.0-rc2 --virtualbox-share-folder
(https://github.com/docker/machine/pull/3798)
Did anything happen with this? I was able to use @jas99's workaround but it's kind of excruciating.
Most helpful comment
@huguesfontenelle
if using boot2docker
create file bootlocal.sh inside /var/lib/boot2docker; so it will persist and get executing when boot2docker images runs
if target folder not present; create one
mkdir [target folder]
mount the hostfolder; it should be shared with virtualbox already
sudo mount -t vboxsf -o uid=1000,gid=1000 [hostfolder] [target folder]