Kirill G.
Kirill G.

Reputation: 960

Synced folder in vagrant is not syncing in realtime

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.

Upvotes: 31

Views: 34127

Answers (1)

Terry Wang
Terry Wang

Reputation: 13920

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 means rsync-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.

Upvotes: 42

Related Questions