
我查看了 Vagrant 網站上的所有synced_folder 配置...
主機作業系統:Windows 7 來賓作業系統:Ubuntu
這是我的 Vagrantfile 配置:
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "base"
config.vm.hostname = "daison.vagrant.me"
config.vm.network :forwarded_port, guest: 80, host: 8080
config.vm.network :private_network, ip: "192.168.33.10"
config.vm.synced_folder ".", "/vagrant", disabled: true
#config.vm.synced_folder "C:\\Users\\daison\\vagrant\\src\\www", "/var/www"
end
我也做C:\Users\daison\vagrant\> vagrant reload
127.0.0.1:8080 or 192.168.33.10 or daison.vagrant.me:8080
我可以透過運行--來存取我的 Ubuntu 的 apache在我的主機中
因此,透過刪除commented synced_folder
並再次重新載入流浪者。所有IP位址和我的虛擬主機的結果是無法訪問--INT 我的主機
我嘗試訪問vagrant ssh
vagrant@daison: cd /var/www
vagrant@daison: /var/www$ ls
並沒有顯示任何內容...
我還嘗試創建一個folder
只是為了看看synced_folder是否真的有效,即使它凍結了來賓資料夾
vagrant@daison: /var/www$ mkdir thisFolderWillAlsoShareToHost
C:\Users\daison\vagrant\src\www
然後在我創建的資料夾中在我的主機中。
我還嘗試將synced_folders更改為"/vagrant/sample"
只是為了測試在重新加載流浪漢後是否/vagrant/sample
會與 凍結相同。/var/www
結果是;我可以存取網頁伺服器,當然它不屬於/var/www
,但使用ls
內部/vagrant/sample
也會凍結。
也許有人可以幫忙?謝謝你!
答案1
從您描述問題的方式來看,聽起來您在來賓上創建了一些網站,設定了同步資料夾,並期望 vagrant 在主機和來賓之間執行雙向同步。事情不是這樣的。啟用同步資料夾的作用是將主機中的資料夾安裝到來賓中。來自主機的內容掩蓋了訪客上的任何現有內容。這就是我的意思:
沒有同步資料夾
> dir C:\Users\daison\vagrant\src\www
a_file_on_the host
$ ls /var/www
a_file_on_the_guest
與這些資料夾同步。
> dir C:\Users\daison\vagrant\src\www
a_file_on_the host
$ ls /var/www
a_file_on_the host
如果您在同步資料夾時從來賓中建立了新文件
> dir C:\Users\daison\vagrant\src\www
a_file_on_the host
file_created_while_synced
$ ls /var/www
a_file_on_the host
file_created_while_synced
停用同步資料夾,現在您會看到
> dir C:\Users\daison\vagrant\src\www
a_file_on_the host
file_created_while_synced
$ ls /var/www
a_file_on_the_guest
因此,如果您的網站是在訪客中建立的,則在您同步時它們將不再可用/var/www。這就是網頁伺服器「凍結」的原因。