Vagrant:如何将文件夹从访客同步回主机?

标签 vagrant virtualbox

为什么,因为在 guest 中通过旧版编辑器工作和编辑代码很困难。 vagrant 的全部目的就是让开发者更容易,对吧:)?

因此,我请有人在这种情况下指导我:

  • 需要参与一个项目。这是 git 仓库。需要mysql、php等。
  • 虚拟机运行良好(已提供)
  • 但是通过 ssh 和“旧版”编辑器编辑此存储库中的文件并不那么容易。想使用最喜欢的 IDE。

VM 存储库位于 /home/vagrant/src 中。 我希望它在主机的 ../src 中可见/可编辑。

我阅读了文档并将其放入 Vagranfile 中:

config.vm.synced_folder '../src', '/home/vagrant/src'

这个“有效”,除了它用 ../src 中的空内容覆盖 /home/vagrant/src 中的所有内容。

有什么解决办法吗? 我考虑了通过 git 克隆存储库(通过 github 公开提供)并将文件夹同步到虚拟机的可能性,但这感觉不对并且也会丢失生产配置。

最佳答案

似乎您正在寻找双向同步。如果我的理解是正确的 answer会帮助你。请注意,我尚未测试这些。看来关键是使用virtualbox同步type

type (string) - The type of synced folder. If this is not specified, Vagrant will automatically choose the best synced folder option for your environment. Otherwise, you can specify a specific type such as "nfs".

config.vm.synced_folder '../src', '/home/vagrant/src', type: "virtualbox"

然后再根据this doc ,

If you are using the Vagrant VirtualBox provider, then VirtualBox shared folders are the default synced folder type. These synced folders use the VirtualBox shared folder system to sync file changes from the guest to the host and vice versa.

因此我不确定为什么你的默认类型不是 virtualbox。无论如何,我想这值得一试。进一步深入文档,文档中解释的虚拟框类型似乎存在一个错误。请关注steps here如果您要使用虚拟盒同步类型。

关于Vagrant:如何将文件夹从访客同步回主机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27384596/

相关文章:

ssh - 无法 ssh 到 vagrant + virtualbox(来自 vmware)

php - Laravel 5.2 上的 MySQL 连接

ssh - 无法使用 Ansible Playbook 在 Vagrant 上通过 SSH 连接到主机

internet-explorer-8 - 在 Virtual Box VM 上安装 IE 8?

node.js - 关闭 ubuntu 终端后 npm 会自行删除吗?

php - Vagrant ,找不到 Apache 文件

ssh - Vagrant ssh 连接到主机 127.0.0.1 :2222 port 22: Bad file number

windows - Virtualbox 中 Windows 10 中的麦克风

linux - 按组名、用户名和上次登录 linux 管理用户帐户

docker - 使 docker 机器在 Windows 中的主机名下可用