2016-07-08 53 views
1

最近,我試圖設置一個VirtualBox作爲虛擬機提供程序的Vagrant框。 在我的第一次嘗試中,Vagrant正確創建了虛擬框,但由於某些廚師錯誤而失敗。失敗的Vagrant重新運行VirtualBox給出了錯誤

我解決由廚師指出錯誤,並再次重新進行了無業遊民了命令,但這個時候,我得到了以下錯誤:

Vagrant cannot forward the specified ports on this VM, since they would collide with some other application that is already listening on these ports.

什麼好像發生故障時,流浪漢沒有清理端口,它與垂直框相關。我甚至嘗試從它創建的Virtual Boxes目錄中刪除.vagrant目錄和機器。仍然得到相同的錯誤。只有這樣我才能夠通過更改流浪文件中的端口轉發來運行它。

請讓我知道是否有任何方式強迫流浪漢自動正確/清潔設置失敗;因爲我不想因爲許多原因而發生失敗時改變流浪文件。

在此先感謝。

回答

2

有一個auto_correct選項,您可以使用

Vagrant.configure("2") do |config| 
    config.vm.network "forwarded_port", guest: 80, host: 8080, 
    auto_correct: true 
end 

https://www.vagrantup.com/docs/networking/forwarded_ports.html

It is common when running multiple Vagrant machines to unknowingly create forwarded port definitions that collide with each other (two separate Vagrant projects forwarded to port 8080, for example). Vagrant includes built-in mechanism to detect this and correct it, automatically.

Port collision detection is always done. Vagrant will not allow you to define a forwarded port where the port on the host appears to be accepting traffic or connections.

Port collision auto-correction must be manually enabled for each forwarded port, since it is often surprising when it occurs and can lead the Vagrant user to think that the port was not properly forwarded. Enabling auto correct is easy:

The final :auto_correct parameter set to true tells Vagrant to auto correct any collisions. During a vagrant up or vagrant reload, Vagrant will output information about any collisions detections and auto corrections made, so you can take notice and act accordingly.

相關問題