Vagrant: How to sync folder from guest back to host?
My Vagrantfile
looks like this:
Vagrant.configure(2) do |config|
config.vm.box = "bento/ubuntu-16.04"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network :forwarded_port, guest: 22, host: 10170, id: "ssh"
config.vm.provision :shell, path: "VagrantProvision.sh"
config.vm.synced_folder "./", "/var/beeGame"
end
As you can see here I have the same statement like yours! Here my repo (you can try it like example), and it works for me! I use PhpStorm to open this repo and edit files and all updates automatically and sync from my host machine (my laptop) to guest machine (virtual).
In your case, you're doing all right, and vagrant has to overwrites all contents from /home/vagrant/src
with those from ../src
. It is right behavior!!! You need put your code into src
dir on your host machine (your laptop) not on your guest machine (virtual)!
Seems like you are looking for two way sync. If my understanding is correct this answer will help you. Please note that I have not yet tested these. Seems like the key is to use virtualbox
sync 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"
Then again according to 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.
Therefore I'm not sure why your default type is not virtualbox. Anyway this is worth a shot I guess. Further going into docs there seems to be a bug in virtual box type explained in docs. Please follow the steps here if you are going to use virtual box sync type.