如何使用 VirtualBox 在 Vagrant 中启用双向文件夹同步? [英] How to enable two-way folder sync in Vagrant with VirtualBox?

查看:39
本文介绍了如何使用 VirtualBox 在 Vagrant 中启用双向文件夹同步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段时间没有在 Linux 上使用 Vagrant.当我开始使用新版本 (Vagrant 1.8) 时,我遇到了一个问题:在来宾 VM 中创建的文件没有出现在主机的同步文件夹中.

I haven't used Vagrant on Linux for a while. When I started using the new version (Vagrant 1.8), I was faced with a problem: files created inside the guest VM didn't appear on the host machine's synced folder.

如何强制 Vagrant 将文件从来宾操作系统同步到主机操作系统?

How do I force Vagrant to sync files from the guest OS to the host OS?

推荐答案

根据文档,当 Vagrantfile 中的 type 选项 config.vm.synced_folder 参数未指定时,Vagrant 尝试选择最佳可用选项:

According to documentation, when type option config.vm.synced_folder parameter in Vagrantfile is not specified, Vagrant tries to choose best available option:

type (string) - 同步文件夹的类型.如果未指定,Vagrant 将自动为您的环境选择最佳同步文件夹选项.否则,您可以指定特定类型,例如nfs".

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".

从 Vagrant 1.5 版开始引入新的rsync 同步文件夹"功能.

Starting with version 1.5 Vagrant introduced new "rsync synced folders" feature.

所以在我的例子中,自动选择了 rsync 类型,这是单向同步:从主机到访客.

So in my case type rsync was automatically chosen, which is one-way sync: from host to guest.

为了使文件夹以两种方式同步,我在 Vagrantfile 中添加了显式定义:

To make folders sync in two-way I added explicit definition in my Vagrantfile:

config.vm.synced_folder ".", "/vagrant", type: "virtualbox"

当然,这仅适用于 VirtualBox.

Of course, this will work only for VirtualBox.

双向同步对于工作流很有用,其中来宾计算机上的应用程序创建文件,例如现代 Web 框架中的数据库迁移文件.

Two way sync is useful for workflows, where apllication on guest machine creating files, for example, database migration files in modern web frameworks.

注意:当您的项目有大量文件时,virtualbox 同步文件夹存在已知的性能问题.

Note: virtualbox synced folders have known performance issues when your project has large amount of files.

这篇关于如何使用 VirtualBox 在 Vagrant 中启用双向文件夹同步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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