I am setting up a synced folder in a vagrant machine like shown in cmd dump below and expect that whenever I update the files in this folder on the host machine the updates will be reflected inside guest machine too, however this is not happening.
Here is the dump and evidence of it not happening (I create a sample file and modify it by changing text in in it from test1
to test2
):
mypc:~ user$ cd Projects/synctest/ mypc:synctest user$ ls Vagrantfile mypc:synctest user$ cat Vagrantfile # -*- mode: ruby -*- # vi: set ft=ruby : VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # always use Vagrants insecure key config.ssh.insert_key = false # Setup box config.vm.box = "coreos-stable" # Setup shared folder config.vm.synced_folder ".", "/vagrant" # Setup memory usage config.vm.provider "virtualbox" do |v| v.memory = 2048 end # Define `dev` vm config.vm.define :dev do |dev| end if Vagrant.has_plugin?("vagrant-cachier") config.cache.scope = :box end end mypc:synctest user$ echo "test1" > test.txt mypc:synctest user$ cat test.txt test1 mypc:synctest user$ vagrant up Bringing machine 'dev' up with 'virtualbox' provider... ==> dev: Importing base box 'coreos-stable'... ==> dev: Matching MAC address for NAT networking... ==> dev: Checking if box 'coreos-stable' is up to date... ==> dev: Setting the name of the VM: synctest_dev_1429451824339_35638 ==> dev: Fixed port collision for 22 => 2222. Now on port 2200. ==> dev: Clearing any previously set network interfaces... ==> dev: Preparing network interfaces based on configuration... dev: Adapter 1: nat ==> dev: Forwarding ports... dev: 22 => 2200 (adapter 1) ==> dev: Running 'pre-boot' VM customizations... ==> dev: Booting VM... ==> dev: Waiting for machine to boot. This may take a few minutes... dev: SSH address: 127.0.0.1:2200 dev: SSH username: core dev: SSH auth method: private key dev: Warning: Connection timeout. Retrying... ==> dev: Machine booted and ready! ==> dev: Rsyncing folder: /Users/user/Projects/synctest/ => /vagrant ==> dev: Rsyncing folder: /Users/user/.vagrant.d/cache/coreos-stable/ => /tmp/vagrant-cache ==> dev: Configuring cache buckets... mypc:synctest user$ vagrant ssh CoreOS stable (633.1.0) core@localhost ~ $ cd ../../vagrant/ core@localhost /vagrant $ ls Vagrantfile test.txt core@localhost /vagrant $ cat test.txt test1 core@localhost /vagrant $ exit logout Connection to 127.0.0.1 closed. mypc:synctest user$ cat test.txt test1 mypc:synctest user$ echo "test2" > test.txt mypc:synctest user$ cat test.txt test2 mypc:synctest user$ vagrant ssh Last login: Sun Apr 19 13:57:37 2015 from 10.0.2.2 CoreOS stable (633.1.0) core@localhost ~ $ cd ../../vagrant/ core@localhost /vagrant $ ls Vagrantfile test.txt core@localhost /vagrant $ cat test.txt test1 core@localhost /vagrant $ echo "hi from guest machine" > test.txt core@localhost /vagrant $ cat test.txt hi from guest machine core@localhost /vagrant $ exit logout Connection to 127.0.0.1 closed. mypc:synctest user$ cat test.txt test2 mypc:synctest user$
Is it even supposed to sync realtime? If yes, why is not syncing?
Edit: OS X 10.8.5
, VirtualBox
, coreos
box.
Using SCP. Another way to copy files and folders from host to guest in Vagrant is to use to SCP. Firstly, make sure you have scp installed on your host. If you don't have it, you can install the openssh-clients package if you're using Linux or install Cygwin if you're using Windows.
Windows: C:/Users/USERNAME/. vagrant. d/boxes.
In your Vagrantfile
the synced folder type is default vboxsf
, however, in the vagrant up stdout, it is showing rsync type, I think you need to fix it in the config file.
Assume that you are using rsync type, you should have the following in your Vagrantfile
Vagrant.configure("2") do |config| config.vm.synced_folder ".", "/vagrant", type: "rsync", rsync__exclude: ".git/" end
NOTE: By default,
rsync__auto
is set to true, which meansrsync-auto
will watch and automatically sync this folder.
Run vagrant rsync-auto
and the directory should be in sync between host and guest.
Refer to vagrant docs for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With