Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Folders that are not relative to the Vagrantfile can not be mounted with docker -v #12

Closed
carloslozano opened this issue Jul 13, 2015 · 6 comments

Comments

@carloslozano
Copy link

Problem

When using boot2docker-vagrant-box, sharing folders with docker [create|run] -v <local_folder>:<docker_folder> does not work if the <local_folder> path is not a sub-folder of the folder containing the Vagrantfile.

Steps to Reproduce

  1. mkdir -p /tmp/boot2docker; cd /tmp/boot2docker
  2. vagrant init parallels/boot2docker; vagrant up --provider parallels
  3. docker run -P -v $HOME/shared:/root/shared precise64 su - root -c 'ls -lart /root/shared'

Expected Result

The command at the aforementioned step 3. lists the contents of the $HOME/shared folder mapped to /root/shared.

Actual Result

The command at the aforementioned step 3. yields no results, the folder is empty (not synched).

Environment

  • OS X 10.10.x
  • Vagrant 1.7.2
  • Parallels 10.2.x
  • Parallels provider 1.4.1

Work-around

  1. mkdir -p /tmp/boot2docker; cd /tmp/boot2docker
  2. vagrant init parallels/boot2docker; vagrant up --provider parallels
  3. docker run -P -v /tmp/boot2docker/shared:/root/shared precise64 su - root -c 'ls -lart /root/shared'

If the shared folder is a sub-folder of /tmp/boot2docker (location of Vagrantfile), the share works correctly.

@legal90
Copy link
Collaborator

legal90 commented Jul 14, 2015

@carloslozano Thanks for pointing on this!
To mount Mac host's folder to the container, we need to share this folder with the VM at first.
As you have noticed, currently only . dir is shared (location of Vagrantfile):

config.vm.synced_folder ".", Dir.pwd

config.vm.synced_folder ".", Dir.pwd

That's why only children of . can be mounted to the Docker container.

I think, we should change this behavior and share the entire /Users directory by default, like "boot2docker" and "Docker Machine" projects do. It will cover the most of use cases, including the one you've mentioned above, with $HOME mapping.

P.s. Limitations: we can not share the OS X root (/) and paths like /var, /usr or /tmp because they already exists on Linux filesystem in your boot2docker VM and these mount points will be overridden.

@legal90
Copy link
Collaborator

legal90 commented Jul 14, 2015

@carloslozano Please, try to add this line to your Vagrantfile, do vagrant reload and then try to reproduce an issue:

config.vm.synced_folder "/Users", "/Users"

Does it work for you now?

@carloslozano
Copy link
Author

@legal90 Thanks for your reply. 👍

I think it would be excellent if boot2docker-vagrant-box could emulate the behaviour of the boot2docker virtualbox as closely as possible. It would really facilitate the migration from virtualbox to parallels; I encountered the aforementioned issue during such a migration and couldn't find any reference anywhere to this behaviour/limitation. In the meantime, a note in the documentation with regard to the current caveats would be helpful to avoid others from falling over the same stone 😉

if I understand correctly, to share any sub-paths of /User we must first share this parent path with the boot2docker-vagrant-box, right? This way any /User/* path could be shared (i.e. /Users/<xyz>/mysharedfolder) and be mapped and shared correctly with the docker instance.

As long as the access to the boot2docker-vagrant-box instance is secure, I don't see a problem a with mapping all of /Users by default; the boot2docker-vagrant-box is executing under a specific user and , as such, can only access sub-paths to which it has sufficient permissions. It would a good recommendation to avoid running the boot2docker-vagrant-box as root in this case. 😏

@carloslozano
Copy link
Author

@legal90 I've just tried your recommendation.

Added to Vagrantfile:

config.vm.synced_folder "/Users", "/Users"

Testing:

docker run -P -v /Users/adaptive/tmp:/home/adaptive/tmp <image> df -k

Result:

Filesystem     1K-blocks      Used Available Use% Mounted on
none            40158812   7019148  31076664  19% /
tmpfs            4083856         0   4083856   0% /dev
shm                65536         0     65536   0% /dev/shm
Users          975922976 179816620 796106356  19% /home/adaptive/tmp <--- :smile:
/dev/sda2       40158812   7019148  31076664  19% /etc/hosts
tmpfs            4083856         0   4083856   0% /proc/kcore
tmpfs            4083856         0   4083856   0% /proc/timer_stats

This work-around works for all sub-paths of /Users. 👍

If I also want to share other sub-paths of, for example /Library or /repository, then I understand that I would have to add these parent paths to the Vagrantfile.

config.vm.synced_folder "/Users", "/Users"
config.vm.synced_folder "/Library", "/Library"
config.vm.synced_folder "/repository", "/repository"

Correct? Thanks!

@legal90
Copy link
Collaborator

legal90 commented Jul 14, 2015

if I understand correctly, to share any sub-paths of /User we must first share this parent path with the boot2docker-vagrant-box, right?

If I also want to share other sub-paths of, for example /Library or /repository, then I understand that I would have to add these parent paths to the Vagrantfile.

@carloslozano Yes, you're right. /Users is shared by default in "boot2docker" project and it's described here (section "boot2docker: Shared directories on Mac OS X"): https://blog.docker.com/2014/10/docker-1-3-signed-images-process-injection-security-options-mac-shared-directories/

I'm gonna apply the same behavior to this vagrant box and add short notice to README.md.

legal90 added a commit that referenced this issue Jul 14, 2015
@legal90
Copy link
Collaborator

legal90 commented Jul 15, 2015

Fixed in v1.7.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants