[英]Private Network broken in Vagrant with Docker
我使用默認的Docker Vagrantfile通過Vagrant創建了一個Virtualbox 虛擬機 。 使用vagrant up
構建vagrant up
可以按預期工作,並提供了一個運行框。
然后,我需要轉發端口的功能,並將以下內容添加到Vagrantfile
:
Vagrant::VERSION >= "1.1.0" and Vagrant.configure("2") do |config|
config.vm.network :forwarded_port, :host => 5432, :guest => 5432 # postgres
# ... more port forwardings
end
這行得通,但后來我意識到我需要雙向端口轉發。 我試圖為此創建一個專用網絡,而不是轉發每個端口。 配置中的以下補充應該可以解決問題:
Vagrant::VERSION >= "1.1.0" and Vagrant.configure("2") do |config|
config.vm.network :private_network, ip: "172.17.0.2"
end
但是,這會在創建虛擬機時觸發錯誤:
> vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Clearing any previously set forwarded ports...
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Running 'pre-boot' VM customizations...
[default] Booting VM...
[default] Waiting for machine to boot. This may take a few minutes...
The guest machine entered an invalid state while waiting for it
to boot. Valid states are 'starting, running'. The machine is in the
'poweroff' state. Please verify everything is configured
properly and try again.
If the provider you're using has a GUI that comes with it,
it is often helpful to open that and watch the machine, since the
GUI often has more helpful error messages than Vagrant can retrieve.
For example, if you're using VirtualBox, run `vagrant up` while the
VirtualBox GUI is open.
任何想法如何調試和解決這個問題?
主機操作系統:Arch Linux
VM作業系統:Ubuntu(請參閱上方的Vagrantfile連結)
為了確保橋接網絡的全部功能,請確保還加載了
vboxnetadp
,vboxnetflt
和vboxpci
內核模塊,並安裝了net-tools
軟件包。
問題是,用於在虛擬機中創建專用網絡的內核模塊需要分別加載:
sudo modprobe -a vboxnetadp vboxnetflt
要使此更改在每次重新啟動后永久生效,請將以下行放在/etc/modules-load.d/virtualbox.conf
:
vboxdrv
vboxnetadp
vboxnetflt
需要安裝net-tools
:
sudo pacman -S net-tools
您還需要virtualbox-host-modules
軟件包才能使專用網絡栩栩如生:
sudo pacman -S virtualbox-host-modules
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.