Starting from Vagrant 1.5 you can use rsync
as sync folder method:
Vagrant.configure("2") do |config|
config.vm.synced_folder "test", "/test", type: "rsync",
end
This is unidirectional.
質問
I have been using synced folders in Vagrant for a while, but the behaviour is not what I expected. It seems both changes in the host machines and changes in the guest machine are synced. However, I want syncing to be in only one direction: from the host to the guest. Part of the reason I want to create a Vagrant machine is that, if my code accidentally does something destructive, like deleting itself, I want that behaviour to be contained in a safe environment.
For reference, this is the Vagrantfile I am using:
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "hashicorp/precise32"
config.vm.provision :shell, :path => "bootstrap.sh"
config.vm.network :forwarded_port, host: 8080, guest: 80
config.vm.synced_folder "test", "/test", :nfs => true
config.vm.network "private_network", type: "dhcp"
end
where bootstrap.h just executes apt-get install nfs-common portmap
.
What is the easiest way I can configure unidirectional syncing in Vagrant?
解決
Starting from Vagrant 1.5 you can use rsync
as sync folder method:
Vagrant.configure("2") do |config|
config.vm.synced_folder "test", "/test", type: "rsync",
end
This is unidirectional.