2013-09-03 18:08:28 +00:00
|
|
|
---
|
2016-01-19 18:08:53 +00:00
|
|
|
layout: "docs"
|
2013-09-06 16:50:43 +00:00
|
|
|
page_title: "Basic Usage - Synced Folders"
|
2013-09-03 18:08:28 +00:00
|
|
|
sidebar_current: "syncedfolder-basic"
|
2016-01-19 18:08:53 +00:00
|
|
|
description: |-
|
|
|
|
Synced folders are configured within your Vagrantfile using the
|
|
|
|
"config.vm.synced_folder" method.
|
2013-09-03 18:08:28 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
# Basic Usage
|
|
|
|
|
|
|
|
## Configuration
|
|
|
|
|
|
|
|
Synced folders are configured within your Vagrantfile using the
|
|
|
|
`config.vm.synced_folder` method. Usage of the configuration directive
|
|
|
|
is very simple:
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
# other config here
|
|
|
|
|
|
|
|
config.vm.synced_folder "src/", "/srv/website"
|
|
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
The first parameter is a path to a directory on the host machine. If
|
|
|
|
the path is relative, it is relative to the project root. The second
|
|
|
|
parameter must be an absolute path of where to share the folder within
|
|
|
|
the guest machine. This folder will be created (recursively, if it must)
|
2016-01-19 18:08:53 +00:00
|
|
|
if it does not exist.
|
2013-09-03 18:08:28 +00:00
|
|
|
|
2013-11-27 02:53:28 +00:00
|
|
|
## Options
|
|
|
|
|
2015-07-07 05:00:05 +00:00
|
|
|
You may also specify additional optional parameters when configuring
|
2015-01-22 19:44:14 +00:00
|
|
|
synced folders. These options are listed below. More detailed examples of using
|
|
|
|
some of these options are shown below this section, note the owner/group example
|
|
|
|
supplies two additional options separated by commas.
|
2013-11-27 02:53:28 +00:00
|
|
|
|
|
|
|
In addition to these options, the specific synced folder type might
|
|
|
|
allow more options. See the documentation for your specific synced folder
|
|
|
|
type for more details. The built-in synced folder types are documented
|
|
|
|
in other pages available in the navigation for these docs.
|
|
|
|
|
2013-12-28 20:29:59 +00:00
|
|
|
* `create` (boolean) - If true, the host path will be created if it
|
|
|
|
does not exist. Defaults to false.
|
|
|
|
|
2013-11-27 02:53:28 +00:00
|
|
|
* `disabled` (boolean) - If true, this synced folder will be disabled and
|
2016-01-19 18:08:53 +00:00
|
|
|
will not be setup. This can be used to disable a previously defined synced
|
2013-11-27 02:53:28 +00:00
|
|
|
folder or to conditionally disable a definition based on some external
|
|
|
|
factor.
|
|
|
|
|
|
|
|
* `group` (string) - The group that will own the synced folder. By default
|
2016-01-19 18:08:53 +00:00
|
|
|
this will be the SSH user. Some synced folder types do not support
|
2013-11-27 02:53:28 +00:00
|
|
|
modifying the group.
|
|
|
|
|
|
|
|
* `mount_options` (array) - A list of additional mount options to pass
|
|
|
|
to the `mount` command.
|
|
|
|
|
|
|
|
* `owner` (string) - The user who should be the owner of this synced folder.
|
2016-01-19 18:08:53 +00:00
|
|
|
By default this will be the SSH user. Some synced folder types do not
|
2013-11-27 02:53:28 +00:00
|
|
|
support modifying the owner.
|
|
|
|
|
|
|
|
* `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".
|
|
|
|
|
2016-05-27 12:42:54 +00:00
|
|
|
* `id` (string) - The name for the mount point of this synced folder in the
|
|
|
|
guest machine. This shows up when you run `mount` in the guest machine.
|
|
|
|
|
2013-09-03 18:08:28 +00:00
|
|
|
## Enabling
|
|
|
|
|
|
|
|
Synced folders are automatically setup during `vagrant up` and
|
|
|
|
`vagrant reload`.
|
|
|
|
|
|
|
|
## Disabling
|
|
|
|
|
2014-05-04 13:45:58 +00:00
|
|
|
Synced folders can be disabled by adding the `disabled` option to
|
2013-09-03 18:08:28 +00:00
|
|
|
any definition:
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
config.vm.synced_folder "src/", "/srv/website", disabled: true
|
|
|
|
end
|
|
|
|
```
|
|
|
|
|
2014-05-04 13:46:43 +00:00
|
|
|
Disabling the default `/vagrant` share can be done as follows:
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
config.vm.synced_folder ".", "/vagrant", disabled: true
|
|
|
|
```
|
|
|
|
|
2013-09-03 18:08:28 +00:00
|
|
|
## Modifying the Owner/Group
|
|
|
|
|
|
|
|
By default, Vagrant mounts the synced folders with the owner/group set
|
|
|
|
to the SSH user. Sometimes it is preferable to mount folders with a different
|
|
|
|
owner and group. It is possible to set these options:
|
|
|
|
|
|
|
|
```ruby
|
2013-09-06 16:50:43 +00:00
|
|
|
config.vm.synced_folder "src/", "/srv/website",
|
|
|
|
owner: "root", group: "root"
|
2013-09-03 18:08:28 +00:00
|
|
|
```
|
2015-07-07 05:00:05 +00:00
|
|
|
|
2016-12-01 02:47:08 +00:00
|
|
|
_NOTE: Owner and group IDs defined within `mount_options` will have precedence
|
|
|
|
over the `owner` and `group` options._
|
|
|
|
|
|
|
|
For example, given the following configuration:
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
config.vm.synced_folder ".", "/vagrant", owner: "vagrant",
|
|
|
|
group: "vagrant", mount_options: ["uid=1234", "gid=1234"]
|
|
|
|
```
|
|
|
|
|
|
|
|
the mounted synced folder will be owned by the user with ID `1234` and the
|
|
|
|
group with ID `1234`. The `owner` and `group` options will be ignored.
|
|
|
|
|
2015-07-07 05:00:05 +00:00
|
|
|
## Symbolic Links
|
|
|
|
|
|
|
|
Support for symbolic links across synced folder implementations and
|
|
|
|
host/guest combinations is not consistent. Vagrant does its best to
|
|
|
|
make sure symbolic links work by configuring various hypervisors (such
|
|
|
|
as VirtualBox), but some host/guest combinations still do not work
|
|
|
|
properly. This can affect some development environments that rely on
|
|
|
|
symbolic links.
|
|
|
|
|
|
|
|
The recommendation is to make sure to test symbolic links on all the
|
|
|
|
host/guest combinations you sync folders on if this is important to you.
|