Search code examples
vagrant

vagrant with multiple sync'd folders


Is it possible to set more than one sync'd folder in a vagrantfile? Here's my current config (using vaprobash):

# Use NFS for the shared folder
config.vm.synced_folder ".", "/vagrant/Sites",
          id: "core",
          :nfs => true,
          :mount_options => ['nolock,vers=3,udp,noatime']

# Use NFS for the shared folder
config.vm.synced_folder "../Code", "/vagrant/Code",
          id: "core",
          :nfs => true,
          :mount_options => ['nolock,vers=3,udp,noatime']

Only the second mapping gets loaded, the other is ignored-- so I end up with a /vagrant/Code directory mapped properly, but no vagrant/Sites


Solution

  • 2021 Update:

    In 2021 no need for unique Id or being nfs, just list your synced folders:

    config.vm.synced_folder ".", "/vagrant/Sites"
    config.vm.synced_folder "../Code", "/vagrant/Code"
    

    Original answer:

    I just needed to set a unique ID for each mount, and then reload the vagrant box.

    # Use NFS for the shared folder
    config.vm.synced_folder ".", "/vagrant/Sites",
          id: "sites", # <--- this ID must be unique
          :nfs => true,
          :mount_options => ['nolock,vers=3,udp,noatime']
    
    # Use NFS for the shared folder
    config.vm.synced_folder "../Code", "/vagrant/Code",
          id: "code", # <--- different from this one
          :nfs => true,
          :mount_options => ['nolock,vers=3,udp,noatime']