linux - 使用 Docker 在 Vagrant 中破坏专用网络

标签 linux networking vagrant archlinux docker

我使用默认的 Docker Vagrantfile 通过 Vagrant 创建了一个 Virtualbox 虚拟机.使用 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)

最佳答案

来自Arch Linux Wiki :

To ensure full functionality of bridged networking, ensure that the vboxnetadp, vboxnetflt and vboxpci kernel modules are loaded too and that the net-tools package is installed.

内核模块

问题是在虚拟机中创建专用网络的内核模块需要单独加载:

sudo modprobe -a vboxnetadp vboxnetflt

要使此更改在每次重新启动后永久生效,请将以下行放入 /etc/modules-load.d/virtualbox.conf:

vboxdrv
vboxnetadp
vboxnetflt

net-tools 需要安装:

sudo pacman -S net-tools

您还需要 virtualbox-host-modules 包来激活私有(private)网络:

sudo pacman -S virtualbox-host-modules

关于linux - 使用 Docker 在 Vagrant 中破坏专用网络,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20154889/

相关文章:

linux - nginx 作为缓存代理不缓存任何东西

docker - 从 Vagrant 机器连接到 Redis Docker 容器

node.js - 从 node.js 配置 VM 实例的推荐方法和工具?

python - 使用 pip 升级最初通过 apt 安装的包

c++ - 通过 execvp : StrictHostKeyChecking=no: unknown option 运行 rsync

linux - 查找包含 '\N abcd ' 的行

java - 无法通过使用 Jsprit 向服务提供时间窗口来获得正确的优化路线

networking - 在 Go 中将结构转换为字节 slice 的紧凑方法是什么?

Apache:如何使用负载均衡器和 2 个服务器编写 X-Forwarded-For?

vagrant:获取 C7.6.1810-base 的存储库数据时出错,未找到存储库