How to launch qemu-kvm from inside a Docker container?
docker --privileged
Some working commands from Ubuntu 17.10 host, Docker 1.13.1:
sudo docker run --name ub16 -i --privileged -t ubuntu:16.04 bash
Then inside Docker:
apt-get update -yapt-get install qemu -yqemu-system-x86_64qemu-system-x86_64 \ -append 'root=/dev/vda console=ttyS0' \ -drive file='rootfs.ext2.qcow2,if=virtio,format=qcow2' \ -enable-kvm \ -kernel 'bzImage' \ -nographic \;
Root file system and bzImage generated with this setup.
--device=/dev/kvm
Adding to the previous answer: Using --privileged
may open up too many permissions for your use case. I have been able to run qemu with kvm and without privileges using the device parameter instead.
Try the following commands:
docker run --device=/dev/kvm -it ubuntu bash
Inside docker:
apt-get update -yapt-get install -y qemu-system-x86qemu-system-x86_64 \ -append 'root=/dev/vda console=ttyS0' \ -drive file='rootfs.ext2.qcow2,if=virtio,format=qcow2' \ -enable-kvm \ -kernel 'bzImage' \ -nographic \;
Easy. You need run privileged container, ensure that you have /dev/kvm node in container, install all packages to serve kvm(libvirt, quemu, whatever else) - that is all you need. See https://github.com/sivaramsk/docker-kvm for reference.