From 343b79a659678e1e53ee2ad6ac3856ecdb2c30cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauri=20V=C3=B5sandi?= Date: Fri, 11 Jun 2021 07:44:26 +0000 Subject: [PATCH] Fix macvtap issues and move to network_mode: host --- Dockerfile | 5 +++-- README.md | 10 ++++++++++ entrypoint.sh | 22 +++++++++++++--------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3d1e230..db8e1cf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,5 @@ -FROM alpine -RUN apk add qemu-system-x86_64 qemu-modules bash +FROM ubuntu +# iproute2 in Alpine linux does not properly handle macvtap interfaces +RUN apt-get update && apt-get install -y qemu-kvm bash iproute2 COPY entrypoint.sh /entrypoint.sh ENTRYPOINT /entrypoint.sh diff --git a/README.md b/README.md index cfffe08..1728e93 100644 --- a/README.md +++ b/README.md @@ -24,3 +24,13 @@ Insert Jenkins or your favourite CI/CD software SSH public keys into `C:\ProgramData\ssh\administrators_authorized_keys` and adjust ACL-s as described [here](https://www.concurrency.com/blog/may-2019/key-based-authentication-for-openssh-on-windows) Use the resulting virtual machine disk image with this Docker image. + + +# Debugging + +If you can't ping the VM from host, make sure bridge mode is used +on the macvlanX interface: + +``` +ip -d link show type macvtap +``` diff --git a/entrypoint.sh b/entrypoint.sh index 17963b9..5a2d5a5 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,14 +2,17 @@ set -x set -e -# Create macvlan interface on Docker's eth0 -ip link add link eth0 name macvtap0 type macvtap mode bridge -ip link set dev macvtap0 address ${MAC:?} -ip link set macvtap0 up +PARENT=bond0.1 +MACVTAP=macvtap$OFFSET + +! ip link delete $MACVTAP +ip link add link $PARENT name $MACVTAP type macvtap mode bridge +ip link set dev $MACVTAP address ${MAC:?} +ip link set $MACVTAP up # No udev in Docker -IFS=: read major minor < <(cat /sys/devices/virtual/net/macvtap0/tap*/dev) -DEV=/dev/tap$(cat /sys/class/net/macvtap0/ifindex) +IFS=: read major minor < <(cat /sys/devices/virtual/net/$MACVTAP/tap*/dev) +DEV=/dev/tap$(cat /sys/class/net/$MACVTAP/ifindex) rm -fv $DEV mknod $DEV c $major $minor @@ -23,7 +26,8 @@ mknod $DEV c $major $minor -drive if=none,id=hd,file=/data/image.bin,snapshot=on,format=raw \ -device scsi-hd,drive=hd \ -usb \ - -device usb-ehci,id=ehci \ + -device usb-ehci,id=ehci \ -device usb-tablet,bus=usb-bus.0 \ - -vnc :0 \ - -netdev tap,id=hostnet0,vhost=on,fd=9 9<>$DEV + -netdev tap,id=hostnet0,fd=9 9<>$DEV \ + -nographic -vga qxl +# -vnc :$OFFSET