可以共享你想要的任何文件夾。你只需要在Vagrantfile文件中說出你想要與猜測共享的文件夾
在這種情況下,我創建一個名爲的數據文件夾,因爲默認情況下這個文件夾不存在。這是我的項目結構。數據文件夾和Vagrantfile位於相同的目錄級別。
.
├── attributes
├── Berksfile
├── Berksfile.lock
├── chefignore
├── **data**
│ └── **hello**
├── definitions
├── files
│ └── default
├── Gemfile
├── Gemfile.lock
├── libraries
├── LICENSE
├── metadata.rb
├── providers
├── README.md
├── recipes
│ ├── default.rb
│ └── gem_sources.rb
├── resources
├── templates
│ └── default
├── test
│ └── integration
│ └── default
├── Thorfile
└── **Vagrantfile**
這是Vagrantfile文件配置。
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
config.vm.hostname = "ubuntu"
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "ubuntu-12.04"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
config.vm.synced_folder "data", "/vagrant_data"
end
數據文件夾中的所有數據都可以被猜測中的vagrant_data文件夾訪問。你可以看到hello文件。
[email protected]:~/Desktop/stack$ vagrant ssh
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic-pae i686)
* Documentation: https://help.ubuntu.com/
Welcome to your Vagrant-built virtual machine.
Last login: Sun Jan 19 13:20:49 2014 from 10.0.2.2
[email protected]:~$ cd /vagrant_data/
[email protected]:/vagrant_data$ ls
hello
[email protected]:/vagrant_data$
我希望這對你有所幫助。 對不起,我的英語
我該如何在Vagrantfile中做到這一點? – Contechtions
@Contechtions我更新了我的答案。 – mariodev