Generic container for launching a Virtual Machine inside a Docker container.
Features:
docker logsPartially based on RancherVM project.
AUTO_ATTACH variable:
AUTO_ATTACH is set to yes, then all the container interfaces are attached to the VM. This is the typical use case.AUTO_ATTACH is set to no, a list of interfaces have to be declared in the ATTACH_IFACES variable. This is useful when launching the container with net=host flag, and only a subset of network interfaces need to be attached to the container./image/image (no extension)docker attach$ docker run \
--name kvm \
-td \
--privileged \
-v /path_to/image_file.qcow2:/image/image \
-e AUTO_ATTACH=yes \
bbvainnotech/kvm:latest
Before running the container, it is needed to create the networks:
$ docker network create --driver=bridge network1 --subnet=172.19.0.0/24
$ docker network create --driver=bridge network2 --subnet=172.19.2.0/24
Then, create the container and attach the network prior to start the container:
$ docker create \
--name container_name \
-td \
--privileged \
--network=network1 \
-v /path_to/image_file.qcow2:/image/image \
-e AUTO_ATTACH=yes \
bbvainnotech/kvm:latest
$ docker network connect network2 container_name
$ docker start container_name
$ docker run \
--name container_name \
-net=host \
-td \
--privileged \
-v /path_to/image_file.qcow2:/image/image \
-e AUTO_ATTACH=yes \
bbvainnotech/kvm:latest
Passing bash keyword as argument to the container will launch a bash shell:
$ docker run \
-ti \
--privileged \
-v /path_to/image_file.qcow2:/image/image \
-e AUTO_ATTACH=yes \
bbvainnotech/kvm:latest
If the container has more than one IP configured in a given interface, the user can select which one to use. The SELECTED_NETWORK environment variable is used to select that IP. This env variable must be in the form IP/MASK (e.g. 1.2.3.4/24).
If this env variable is not set, the IP to be given to the VM is the first in the list for that interface (default behaviour).
This usecase is found when working with Kubernetes: Kubernetes assigns two IP addresses to the docker eth0 interface.
When this env variable is set to yes, the entrypoint will scan all the vNICs present in the Docker container, and it will configure the hosted VM to get as many vNICs as the host container.
If this variable is set to no, only the interface names specified in the env variable $ATTACH_IFACES will be connected to the guest VM. Interfaces shall be separated by spaces (eg. ATTACH_IFACES='eth0 eth2').
If AUTO_ATTACH is set to no and no interfaces are defined, the VM will start with no NICs (and thus no vtap devices connected to container interfaces).
This var controls the invocation parameters for dnsmasq daemon, used to give IP addresses to the VM. See dnsmasq's man page for info about available options.
It's specially useful the following options when debugging dnsmasq behaviour:
--log-facility=/var/log/dnsmasq.log --log-dhcp
When this env varable is set to yes, the verbosity is increased.
This container uses macvlan devices to setup network connectivity. If an old kernel or limited host is used, it is possible to use linux bridge by setting the variable USE_NET_BRIDGES to yes.
Privileged mode (--privileged) is needed in order for KVM to access to macvtap devices see issue #3 for further information.
If you get the following error from KVM:
qemu-kvm: -netdev tap,id=net0,vhost=on,fd=3: vhost-net requested but could not be initialized
qemu-kvm: -netdev tap,id=net0,vhost=on,fd=3: Device 'tap' could not be initialized
you will need to load the vhost-net kernel module in your dockerhost (as root) prior to launch this container:
# modprobe vhost-net
This is probed to be needed when using RancherOS.
Content type
Image
Digest
Size
105 MB
Last updated
about 9 years ago
docker pull voobscout/kvm