【问题标题】:Private Network broken in Vagrant with Docker使用 Docker 在 Vagrant 中破坏专用网络
【发布时间】:2013-12-07 22:12:22
【问题描述】:

我使用默认的Docker Vagrantfile 通过 Vagrant 创建了一个 Virtualbox vm。使用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

但是,这会在创建 vm 时触发错误:

> 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)

【问题讨论】:

    标签: linux networking vagrant archlinux docker


    【解决方案1】:

    来自Arch Linux Wiki

    为确保桥接网络的全部功能,请确保 vboxnetadpvboxnetfltvboxpci 内核模块也已加载,并且 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-18
      • 2017-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-23
      • 2019-04-13
      相关资源
      最近更新 更多