Vagrant共享和同步文件夹
我创建了一个包含以下内容的Vagarant文件:Vagrant共享和同步文件夹,vagrant,Vagrant,我创建了一个包含以下内容的Vagarant文件: Vagrant::Config.run do |config| config.vm.define :foo do |cfg| cfg.vm.box = 'foo' cfg.vm.host_name = "foo.localdomain.local" cfg.vm.network :hostonly, "192.168.123.10" end Vagrant.configure("2") do |cf
Vagrant::Config.run do |config|
config.vm.define :foo do |cfg|
cfg.vm.box = 'foo'
cfg.vm.host_name = "foo.localdomain.local"
cfg.vm.network :hostonly, "192.168.123.10"
end
Vagrant.configure("2") do |cfg|
cfg.vm.customize [ "modifyvm", :id , "--name", "foo" , "--memory", "2048", "--cpus", "1"]
cfg.vm.synced_folder "/tmp/", "/tmp/src/"
end
end
在vagrant up
或vagrant reload
之后,我得到:
[foo] Attempting graceful shutdown of VM...
[foo] Setting the name of the VM...
[foo] Clearing any previously set forwarded ports...
[foo] Fixed port collision for 22 => 2222. Now on port 2200.
[foo] Creating shared folders metadata...
[foo] Clearing any previously set network interfaces...
[foo] Preparing network interfaces based on configuration...
[foo] Forwarding ports...
[foo] -- 22 => 2200 (adapter 1)
[foo] Booting VM...
[foo] Waiting for VM to boot. This can take a few minutes.
[foo] VM booted and ready for use!
[foo] Setting hostname...
[foo] Configuring and enabling network interfaces...
[foo] Mounting shared folders...
[foo] -- /vagrant
我的问题是:
/Vagrant
共享文件夹?我读到共享文件夹不推荐使用同步文件夹,而且我从未在我的文件中定义过任何共享文件夹vboxsf
(如果存在大量文件/目录,则存在已知的性能问题)
Vagrantfile目录在guest中作为/vagrant
装入
Vagrant正在将当前工作目录(Vagrantfile所在的位置)装载为来宾中的/Vagrant
,这是默认行为
看
注意:默认情况下,Vagrant会将您的项目目录(包含Vagrant文件的目录)共享给/Vagrant
您可以通过在vagrant文件中添加cfg.vm.synced_文件夹“.”,“/vagrant”,disabled:true
来禁用此行为
为什么同步文件夹不工作
根据输出,主机上的/tmp
在启动期间未装载
使用VAGRANT\u INFO=debug-VAGRANT-up
或VAGRANT\u INFO=debug-VAGRANT-reload
启动VM,以获取有关未装入同步文件夹原因的更多输出。可能是权限问题(主机上/tmp
的模式位应为drwxrwxrwt
)
我用下面的方法做了一个快速测试,它成功了(我用了opscode bento raring vagrant base box)
config.vm.synced_文件夹“/tmp”、“/tmp/src”
输出
$ vagrant reload
[default] Attempting graceful shutdown of VM...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Available bridged network interfaces:
1) eth0
2) vmnet8
3) lxcbr0
4) vmnet1
What interface should the network bridge to? 1
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Running 'pre-boot' VM customizations...
[default] Booting VM...
[default] Waiting for VM to boot. This can take a few minutes.
[default] VM booted and ready for use!
[default] Configuring and enabling network interfaces...
[default] Mounting shared folders...
[default] -- /vagrant
[default] -- /tmp/src
在虚拟机中,您可以看到/tmp/src-type-vboxsf(uid=900,gid=900,rw)上的装载信息/tmp/src
vagrant-up--debug
或vagrant-reload--debug
可能使用fullcfg.VM.synced_文件夹“,/vagrant”,禁用:true禁用默认装载非常有用,thanksI在虚拟机之外有一个主机文件夹“public”文件夹,已正确设置为sync,但在计算机启动时不会装载该文件夹。VAGRANT\u INFO=debug VAGRANT reload
帮了我的忙,现在它每次都会装载。谢谢!我必须添加config.vm.synced\u文件夹。“/VAGRANT”,已禁用:false
到Vagrantfile
使其工作。我想默认值已经改变了。