diff --git a/kvm/Dockerfile b/kvm/Dockerfile index 1d1b917..bd6acb4 100644 --- a/kvm/Dockerfile +++ b/kvm/Dockerfile @@ -11,11 +11,13 @@ LABEL maintainer "Jessie Frazelle " RUN apt-get update && apt-get install -y \ dnsmasq \ + gir1.2-spiceclientgtk-3.0 \ iproute2 \ iptables \ libgl1-mesa-dri \ libgl1-mesa-glx \ libvirt-daemon-system \ + procps \ python-gi \ python-ipaddr \ qemu-kvm \ @@ -28,4 +30,4 @@ RUN apt-get update && apt-get install -y \ COPY ./start.sh /start.sh ENTRYPOINT ["/start.sh"] -CMD ["libvirtd"] +CMD ["virt-manager", "--no-fork"] diff --git a/kvm/start.sh b/kvm/start.sh index e864718..4f587f7 100755 --- a/kvm/start.sh +++ b/kvm/start.sh @@ -3,11 +3,17 @@ set -e set -o pipefail # add the correct user perms +echo "Adding the user groups..." gpasswd -a root libvirt gpasswd -a root kvm chown root:kvm /dev/kvm +# allow root user to use qemu +echo 'user = "root"' >> /etc/libvirt/qemu.conf +echo 'group = "root"' >> /etc/libvirt/qemu.conf + # create the bridge for networking +echo "Creating the bridge for networking..." ip link add name virt0 type bridge ip link set dev virt0 up bridge link @@ -15,10 +21,28 @@ ip addr add dev virt0 172.20.0.1/16 iptables -t nat -A POSTROUTING -s 172.20.0.1/16 -j MASQUERADE # start the virtlogd daemon -exec virtlogd --daemon & +echo "Starting virtlogd..." +virtlogd & + +# start libvirtd +echo "Starting libvirtd..." +libvirtd & + +# put in a sleep for services to start +echo "Sleeping while services start..." +sleep 5 # start the default networking -virsh net-start default || true +echo "Creating the default networking..." +virsh net-start default +# import existing vms +echo "Importing any existing VMs..." +for f in /root/kvm/*.xml; do + echo "Importing $(basename $f)..." + virsh define "$f" +done + +echo "Starting virt-manager..." # shellcheck disable=SC2068 exec $@