2013-12-20 55 views
0

我開始了一個新的Vagrant項目來學習一些Django。虛擬機運行良好,一切正常,但我不知道如何訪問我的虛擬機內的文件,以使用像Sublime這樣的文本編輯器進行編輯。如何訪問Vagrant VM的主目錄?

在VM上,cd/vagrant進入我的桌面流浪者文件夾。但是,我找不到我的VM主目錄文件夾存儲在我的主機上。

/遊民

-Vagrantfile 
-cookbooks 
--apache2 
--apt 
--build-essential 
--git 
--vim 

〜$

-build 
-django_project 
--django_project 
--manage.py 
-postinstall.sh 

回答

1

首頁上您的客人目錄未共享,則需要在Vagrantfile手動設置。

編輯:

的外觀,文件,取消這條線內(讀取線以上的註釋,以獲取更多詳細信息):

# config.vm.synced_folder "../data", "/vagrant_data" 
+0

我該如何在Vagrantfile中做到這一點? – Contechtions

+0

@Contechtions我更新了我的答案。 – mariodev

0

可以共享你想要的任何文件夾。你只需要在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$ 

我希望這對你有所幫助。 對不起,我的英語