├── Dockerfile ├── README.md └── entrypoint.sh /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:14.04.4 2 | 3 | RUN apt-get -y update && DEBIAN_FRONTEND=noninteractive apt-get -y install kvm qemu-kvm libvirt-bin bridge-utils libguestfs-tools 4 | 5 | ADD entrypoint.sh /entrypoint.sh 6 | 7 | CMD /entrypoint.sh 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # docker-kvm 2 | Run qemu/kvm vm's inside a docker container 3 | 4 | If you want need full fledged kvm working under docker, please check rancheros. This is a simple implementation of kvm/qemu inside docker, but functional. The ports that need to be exposed from the VM can be exposed like docker's -p, which can be exposed to the host with -p of the docker command. 5 | 6 | To run container, 7 | 8 | docker run --privileged -p 3022:3022 -e PORTMAP="-net user,hostfwd=tcp::3389-:3389 -redir tcp:3022::22" -e RAM_SIZE=2048 -e IMAGE_PATH=/ubuntu.img -v /home/siva/ubuntu.img:/ubuntu.img sivaramsk/docker-kvm:0.1 9 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | RAM_SIZE=$1 5 | IMAGE_PATH=$2 6 | 7 | # Create the kvm node (required --privileged) 8 | if [ ! -e /dev/kvm ]; then 9 | mknod /dev/kvm c 10 $(grep '\' /proc/misc | cut -f 1 -d' ') 10 | fi 11 | 12 | #PORT EXPOSE FORMAT 13 | #-net user,hostfwd=tcp::3389-:3389 -redir tcp:3022::22 14 | 15 | if [[ -z $RAM_SIZE ]] || [[ -z $IMAGE_PATH ]]; then 16 | echo "Please define $RAM_SIZE and $IMAGE_PATH to launch the kvm" 17 | exit 18 | fi 19 | 20 | qemu-system-x86_64 -net nic,model=rtl8139 $PORTMAP -m $RAM_SIZE -localtime -smp 2 -k en-us -vnc :0 -hda $IMAGE_PATH -nographic 21 | --------------------------------------------------------------------------------