Sharing a folder in vagrant removes guest folder contents

1

1

Still learning a bit about Vagrant, but here it goes. I have a pretty standard guest vm that has some software installed. I would like to access a few directories within the guest in a read/write fashion. So I added the config for a shared folder as follows:

config.vm.share_folder "test", "/home/vagrant/test", "./test"

Keep in mind I have content in my test folder. I need to be able to view and update that from the host. However, when I 'vagrant reload' with the empty host directory called test, all of the content on my guest is removed.

Is it possible to create a shared folder in which I can access content on the guest without destroying existing content?

DocWatson

Posted 2013-02-28T18:31:18.887

Reputation: 111

If you want to share from guest to host, you can still do it one of the standard ways e.g. with a Samba share, or fuse-ssh. One of the advantages of vagrant mapping a host folder to the VM is you can easily share files between VMs via the host. This way round also makes it easier to edit files on the host but test on the guest, a common development pattern. – Ben XO – 2014-11-24T17:24:26.907

1Shared folders share a folder on the host machine with the guest machine, not the other way around. – heavyd – 2013-03-02T00:04:43.733

Thats what I was afraid of, thanks for the response. – DocWatson – 2013-03-04T17:13:18.260

Answers

2

In case someone else comes by this problem, shared folders are indeed synced in both directions (from host to guest and from guest to host) but it depends on the type option.

In Linux this works out of the box without specifying the type option:

  1. Log into the virtual machine.
  2. Add a file in your shared folder e.g. /home/vagrant/somefile.
  3. Check your host folder and you will find the new file.

The problem comes in when you try to sync a folder after provisioning the virtual machine. In such case the guest folder will be sync'd to the host folder, which is empty.

Read the different types of shared folders.

Camilo

Posted 2013-02-28T18:31:18.887

Reputation: 121