我正在尝试在 Docker 中运行 virtualbox 以使用 vagrant。我尝试使用 Ubuntu 来实现这一点。这是我的 Dockerfile:
FROM ubuntu
RUN apt-get update
RUN apt-get install -y software-properties-common python-software-properties
RUN add-apt-repository 'deb http://download.virtualbox.org/virtualbox/debian trusty contrib'
RUN add-apt-repository 'deb http://de.archive.ubuntu.com/ubuntu trusty main restricted universe multiverse'
RUN apt-get update
RUN apt-get install -y wget linux-headers-generic
RUN wget http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add -
RUN apt-get update
RUN apt-get install -y gcc virtualbox dkms virtualbox-dkms
RUN wget https://dl.bintray.com/mitchellh/vagrant/vagrant_1.7.1_x86_64.deb
RUN dpkg -i vagrant_1.7.1_x86_64.deb
如果我然后运行virtualbox
,我会得到:
WARNING: The character device /dev/vboxdrv does not exist.
Please install the virtualbox-dkms package and the appropriate
headers, most likely linux-headers-.
You will not be able to start VMs until this problem is fixed.
Failed to open the X11 display!
如您所见,我已经尝试使用 安装我的标头apt-get install linux-headers-generic
。但尝试使用 uname 安装:apt-get install linux-headers-uname -r
不起作用:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package linux-headers-3.16.7-tinycore64
E: Couldn't find any package by regex 'linux-headers-3.16.7-tinycore64'
我到处都找不到 linux-headers-3.16.7-tinycore64。用 Google 搜索过,但没找到,甚至在 linux tinycore 网站上也没有找到。
感谢您的帮助!
答案1
您需要在主机系统上安装内核模块,而不是在 docker 镜像中。
sudo apt-get install linux-headers-generic virtualbox-dkms
然后测试内核模块是否已加载:
sudo /etc/init.d/virtualbox status
VirtualBox kernel modules are loaded.
然后您应该能够通过挂载 /dev/vboxdrv 来运行 docker 容器:
docker run -it -v /dev/vboxdrv:/dev/vboxdrv image-name
看VirtualBox 与 Docker 之间的区别以 Docker Hub 为例。