I tried running the container in privileged mode, but still the vboxdrv cannot be loaded.
I get
WARNING: The vboxdrv kernel module is not loaded. Eit
Yes, you can. You'll need to make sure you have the kernel module on your host system. I'm running Ubuntu, but I'm sure it'd be similar on other distros:
sudo apt-get install linux-headers-generic virtualbox-dkms
And make sure the kernel module is loaded:
sudo /etc/init.d/virtualbox status
VirtualBox kernel modules are loaded.
Now, run the docker container, and mount /dev/vboxdrv as a volume:
docker run -it -v /dev/vboxdrv:/dev/vboxdrv your/container-image
Edited at 2016-03-27 12:54 UTC
I have the exact same issue and I can successfully dockerize the latest version of VirtualBox with the Extension Pack and phpvirtualbox on CentOS 7.
You have to install tons of dependencies such as kernel-devel, make, gcc and dkms. After finishing the docker build, you MUST run the docker image with these flags you need the flag --privileged=true -v /dev/:/dev/
.--privileged=true
to run the image with the docker version of 1.10.3
For the details, please see my Dockerfile and run.sh
For the details, please have a look my repository especially Makefile, virtualbox.Dockerfile, vboxwebsrv.Dockerfile and phpvirtualbox.Dockerfile
2019:
The key is to use a docker image that has systemd running. I chose jrei/systemd-ubuntu
see here.
docker run -d --privileged \
--name systemd-ubuntu --network=host \
--device /dev/vboxdrv:/dev/vboxdrv \
-v /sys/fs/cgroup:/sys/fs/cgroup:ro \
-v /tmp:/tmp -it jrei/systemd-ubuntu
Inside the container I ran:
apt update
apt -y install wget
apt -y install gnupg2
apt -y install systemd
apt -y install software-properties-common
wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | apt-key add -
wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | apt-key add -
add-apt-repository "deb https://download.virtualbox.org/virtualbox/debian bionic contrib"
apt update
apt -y install virtualbox-6.0
Enjoy :-)