Vagrant 中的符号链接和同步文件夹 [英] Symbolic links and synced folders in Vagrant

查看:48
本文介绍了Vagrant 中的符号链接和同步文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Vagrant 为我的团队提供一个通用的开发环境.主机完全不同:

I want to use Vagrant to provide a common development environment to my team. The hosts are completely different:

  • 有些使用 OS X,有些使用 Linux,有些使用 Windows.
  • 有些使用 VMware,有些使用 VirtualBox.

我们想要在 VM 内部运行 Linux.

Inside of the VM we want to run Linux.

到目前为止,一切都很好.

So far, everything is fine.

现在我们的想法是每个开发人员都可以使用他们选择的 IDE,因此我们引入了一个同步文件夹,在主机和 VM 之间共享源代码.这基本上也有效……除了符号链接.

Now our idea was that each developer shall be able use the IDE of their choice, and hence we have introduced a synced folder that shares the source code between the host and the VM. This basically, works as well … except for symbolic links.

在我们的源代码中,我们确实有一些符号链接,这在 VM 内部的 Linux 中不是问题,但在作为主机的 Windows 上这会导致问题.我们唯一不能做的就是去掉符号链接,所以我们需要另一种方法来解决这个问题.

Inside of our source code we actually do have a few symbolic links, which is not a problem within the Linux inside the VM, but on Windows as host this causes problems. The only thing that we can not do is get rid of the symbolic links, so we need another way to deal with this.

到目前为止,我们已经尝试了多种选择:

So far, we have tried a number of options:

  • 在 Vagrant 的问题中提到了一种解决方法,不幸的是,这仅适用于 VirtualBox并且对运行 VMware 的人没有帮助.到目前为止,我们还没有找到根据使用的提供程序在 Vagrantfile 中运行代码的方法.
  • 我们现在尝试使用 rsync 类型,而不是使用标准共享文件夹.这在 Windows 上有效,但在 OS X 上崩溃并出现许多错误,告诉我们符号链接没有引用(每个符号链接一个错误).
  • 我们考虑过 NFS,但这仅在您不使用 Windows 作为主机时才有效.
  • 我们也考虑过 SMB,但这同样仅适用于作为主机的 Windows.
  • There is a workaround mentioned in an issue of Vagrant, unfortunately this is VirtualBox-only and does not help those who run VMware. So far, we haven't found a way of running code in the Vagrantfile depending on the provider used.
  • Instead of using a standard shared folder we now have tried using the rsync type. This works on Windows, but crashes on OS X with a number of errors telling us that the symlink has no referent (one error per symbolic link).
  • We thought about NFS, but that only works if you do not use Windows as host.
  • We also though about SMB, but this again only works on Windows as host.

我无法想象我们是这个星球上唯一或第一个遇到共享文件夹中多平台主机和符号链接问题的人.

I can not imagine that we are the only or the first persons on this planet to experience problems with multi-platform hosts and symbolic links within the shared folder.

你如何解决这个问题,让我们可以保留符号链接,但仍然使用不同的主机操作系统?

How can you solve this issue, so that we can keep symbolic links, but still use different host operating systems?

推荐答案

出于安全原因,Virtualbox 不允许共享文件夹上的符号链接.要启用符号链接,需要将以下行添加到 Vagrantfile 中的 vm provider 配置块:

Virtualbox does not allow symlinks on shared folders for security reasons. To enable symlinks the following line needs to be added to the vm provider config block in the Vagrantfile:

config.vm.provider "virtualbox" do |v|
    v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]
end

此外,在 windows 上 vagrant up 需要在具有管理员权限的 shell 中执行.无需解决方法.

Additionally, on windows vagrant up needs to be executed in a shell with admin rights. No workarounds necessary.

这篇关于Vagrant 中的符号链接和同步文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆