From 8d0ca4a290e98fb5051d6559ee02d47d316c37d9 Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 17 Jan 2024 16:11:18 +0100 Subject: [PATCH 01/13] docs: Disk pass-through --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 14f5efb5..deabcdae 100644 --- a/readme.md +++ b/readme.md @@ -166,7 +166,7 @@ docker run -it --rm -e "DISPLAY=vnc" -e "BOOT=http://example.com/image.iso" -p 5 Please note that in this mode, the container and the VM will each have their own separate IPs. The container will keep the macvlan IP, and the VM will be reachable via the DHCP IP. - * ### How do I pass-through a disk? + * ### How do I pass-through a disk? It is possible to pass-through disk devices directly by adding them to your compose file in this way: From e294016ab1ceae7011810a80461567c23b028e9b Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 17 Jan 2024 18:12:08 +0100 Subject: [PATCH 02/13] feat: Add nginx configuration --- nginx.conf | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 nginx.conf diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 00000000..95c25b2b --- /dev/null +++ b/nginx.conf @@ -0,0 +1,51 @@ +server { + + listen 8006 default_server; + listen [::]:8006 default_server; + + autoindex on; + server_name _; + tcp_nodelay on; + server_tokens off; + + error_log /dev/null; + access_log /dev/null; + + location / { + + include /etc/nginx/mime.types; + + gzip on; + gzip_vary on; + gzip_proxied any; + gzip_comp_level 5; + gzip_min_length 500; + gzip_disable "msie6"; + gzip_types text/css text/javascript text/xml text/plain text/x-component application/javascript application/json application/xml application/rss+xml font/truetype font/opentype application/vnd.ms-fontobject image/svg+xml; + + expires 30d; + add_header Pragma public; + add_header Cache-Control "public"; + + proxy_hide_header X-Powered-By; + + root /usr/share/novnc; + index vnc_lite.html; + + try_files $uri $uri/ /index.html =404; + + } + + location /websockify { + + proxy_pass http://127.0.0.1:5700/; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_read_timeout 61s; + proxy_connect_timeout 61s; + proxy_send_timeout 61s; + + } + +} From 05a7cecc873b7d76b029b44b33095d5710c562e9 Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 17 Jan 2024 18:21:26 +0100 Subject: [PATCH 03/13] feat: Add nginx and novnc --- Dockerfile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Dockerfile b/Dockerfile index 2cae9250..d14845a3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,7 @@ RUN apt-get update \ wget \ ovmf \ socat \ + nginx \ procps \ iptables \ iproute2 \ @@ -20,10 +21,17 @@ RUN apt-get update \ ca-certificates \ netcat-openbsd \ qemu-system-x86 \ + && novnc="v1.4.0" \ + && wget https://github.com/novnc/noVNC/archive/refs/tags/$novnc.tar.gz -O /tmp/novnc.tar.gz -q \ + && tar -xf /tmp/novnc.tar.gz -C /tmp/ \ + && mkdir -p /usr/share/novnc \ + && mv /tmp/noVNC-$novnc/app /tmp/noVNC-$novnc/core /tmp/noVNC-$novnc/vendor /tmp/noVNC-$novnc/*.html /usr/share/novnc \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* COPY ./src /run/ +COPY nginx.conf /etc/nginx/sites-enabled/novnc.conf + RUN chmod +x /run/*.sh VOLUME /storage From b928d7e0cc40a8e3938a4b15cd9b7fab97cf248d Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 17 Jan 2024 18:24:48 +0100 Subject: [PATCH 04/13] feat: Enable VNC websockets --- src/display.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/display.sh b/src/display.sh index 7bd3253a..8f110ae1 100644 --- a/src/display.sh +++ b/src/display.sh @@ -4,16 +4,14 @@ set -Eeuo pipefail # Docker environment variables : "${GPU:="N"}" # GPU passthrough -: "${DISPLAY:="none"}" # Display type +: "${DISPLAY:="web"}" # Display type case "${DISPLAY,,}" in vnc) DISPLAY_OPTS="-display vnc=:0 -vga virtio" ;; web) - addPackage "novnc" "web-based VNC client" - ln -sfn /usr/share/novnc/vnc_lite.html /usr/share/novnc/index.html - DISPLAY_OPTS="-display vnc=:0 -vga virtio" + DISPLAY_OPTS="-display vnc=:0,websocket=5700 -vga virtio" ;; *) DISPLAY_OPTS="-display $DISPLAY -vga none" @@ -25,7 +23,8 @@ if [[ "$GPU" != [Yy1]* ]] || [[ "$ARCH" != "amd64" ]]; then fi DISPLAY_OPTS="-display egl-headless,rendernode=/dev/dri/renderD128 -vga virtio" -[[ "${DISPLAY,,}" == "vnc" || "${DISPLAY,,}" == "web" ]] && DISPLAY_OPTS="$DISPLAY_OPTS -vnc :0" +[[ "${DISPLAY,,}" == "vnc" ]] && DISPLAY_OPTS="$DISPLAY_OPTS -vnc :0" +[[ "${DISPLAY,,}" == "web" ]] && DISPLAY_OPTS="$DISPLAY_OPTS -vnc :0,websocket=5700" [ ! -d /dev/dri ] && mkdir -m 755 /dev/dri From 8317c9e982e7c5402c360520bc127104c35cc60a Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 17 Jan 2024 18:26:09 +0100 Subject: [PATCH 05/13] feat: Start nginx --- src/entry.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/entry.sh b/src/entry.sh index 1568105a..979e2b01 100755 --- a/src/entry.sh +++ b/src/entry.sh @@ -18,7 +18,7 @@ cd /run trap - ERR if [[ "${DISPLAY,,}" == "web" ]]; then - websockify -D --web /usr/share/novnc/ 8006 localhost:5900 2>/dev/null + nginx -e stderr fi info "Booting image using $VERS..." From d2c85bdf20e67d1594f4d830cc0496f15d14387e Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 17 Jan 2024 18:45:36 +0100 Subject: [PATCH 06/13] Update Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d14845a3..27688ca7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,7 +25,7 @@ RUN apt-get update \ && wget https://github.com/novnc/noVNC/archive/refs/tags/$novnc.tar.gz -O /tmp/novnc.tar.gz -q \ && tar -xf /tmp/novnc.tar.gz -C /tmp/ \ && mkdir -p /usr/share/novnc \ - && mv /tmp/noVNC-$novnc/app /tmp/noVNC-$novnc/core /tmp/noVNC-$novnc/vendor /tmp/noVNC-$novnc/*.html /usr/share/novnc \ + && mv /tmp/noVNC-$novnc/app /tmp/noVNC-$novnc/core /tmp/noVNC-$novnc/vendor /tmp/noVNC-$novnc/package.json /tmp/noVNC-$novnc/*.html /usr/share/novnc \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* From 7f26c3cfa76af905aaae40c872e5c6d68c76ae57 Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 17 Jan 2024 19:15:32 +0100 Subject: [PATCH 07/13] Update Dockerfile --- Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 27688ca7..d15e8752 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,8 +24,9 @@ RUN apt-get update \ && novnc="v1.4.0" \ && wget https://github.com/novnc/noVNC/archive/refs/tags/$novnc.tar.gz -O /tmp/novnc.tar.gz -q \ && tar -xf /tmp/novnc.tar.gz -C /tmp/ \ - && mkdir -p /usr/share/novnc \ - && mv /tmp/noVNC-$novnc/app /tmp/noVNC-$novnc/core /tmp/noVNC-$novnc/vendor /tmp/noVNC-$novnc/package.json /tmp/noVNC-$novnc/*.html /usr/share/novnc \ + && cd /tmp/noVNC-$novnc \ + && mkdir -p /usr/share/novnc \ + && mv app core vendor package.json *.html /usr/share/novnc \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* From bda24ed9518541e493879bf4bf3f61c5ce88ae4f Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 17 Jan 2024 19:17:23 +0100 Subject: [PATCH 08/13] Update nginx.conf --- nginx.conf | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/nginx.conf b/nginx.conf index 95c25b2b..5a4988f2 100644 --- a/nginx.conf +++ b/nginx.conf @@ -11,9 +11,9 @@ server { error_log /dev/null; access_log /dev/null; - location / { + include /etc/nginx/mime.types; - include /etc/nginx/mime.types; + location / { gzip on; gzip_vary on; @@ -23,28 +23,26 @@ server { gzip_disable "msie6"; gzip_types text/css text/javascript text/xml text/plain text/x-component application/javascript application/json application/xml application/rss+xml font/truetype font/opentype application/vnd.ms-fontobject image/svg+xml; - expires 30d; - add_header Pragma public; - add_header Cache-Control "public"; - - proxy_hide_header X-Powered-By; + add_header Cache-Control "no-cache"; root /usr/share/novnc; - index vnc_lite.html; + index vnc.html; - try_files $uri $uri/ /index.html =404; + if ($request_uri = "/") { + return 301 /?resize=scale&autoconnect=true; + } } location /websockify { - proxy_pass http://127.0.0.1:5700/; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection 'upgrade'; - proxy_read_timeout 61s; - proxy_connect_timeout 61s; - proxy_send_timeout 61s; + proxy_pass http://127.0.0.1:5700/; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_read_timeout 61s; + proxy_connect_timeout 61s; + proxy_send_timeout 61s; } From 719e527a2c383ed94536d18a09dd9c31b7788e2e Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 17 Jan 2024 19:20:26 +0100 Subject: [PATCH 09/13] Update docker-compose.yml --- docker-compose.yml | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 8a818c6c..44c5aee3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,22 +1,22 @@ version: "3" services: - qemu: - container_name: qemu - image: qemux/qemu-docker:latest - environment: - DISPLAY: "vnc" - RAM_SIZE: "1G" - CPU_CORES: "1" - DISK_SIZE: "16G" - BOOT: "https://dl-cdn.alpinelinux.org/alpine/v3.19/releases/x86_64/alpine-virt-3.19.0-x86_64.iso" - devices: - - /dev/kvm - device_cgroup_rules: - - 'c *:* rwm' - cap_add: - - NET_ADMIN - ports: - - 2222:22 - - 5900:5900 - stop_grace_period: 2m - restart: unless-stopped + qemu: + container_name: qemu + image: qemux/qemu-docker:latest + environment: + RAM_SIZE: "1G" + CPU_CORES: "1" + DISK_SIZE: "16G" + BOOT: "https://dl-cdn.alpinelinux.org/alpine/v3.19/releases/x86_64/alpine-virt-3.19.0-x86_64.iso" + devices: + - /dev/kvm + device_cgroup_rules: + - 'c *:* rwm' + cap_add: + - NET_ADMIN + ports: + - 2222:22 + - 5900:5900 + - 8006:8006 + stop_grace_period: 2m + restart: unless-stopped From 288c92a8595b02f046f0b5e813bebafbf34362a1 Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 17 Jan 2024 19:22:30 +0100 Subject: [PATCH 10/13] Update readme.md --- readme.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index deabcdae..4c1d6432 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -

QEMU in Docker
+

QEMU
@@ -32,15 +32,13 @@ services: container_name: qemu image: qemux/qemu-docker environment: - DISPLAY: "vnc" BOOT: "https://dl-cdn.alpinelinux.org/alpine/v3.19/releases/x86_64/alpine-virt-3.19.0-x86_64.iso" devices: - /dev/kvm cap_add: - NET_ADMIN ports: - - 2222:22 - - 5900:5900 + - 8006:8006 stop_grace_period: 2m restart: unless-stopped ``` From 25835b1928a22426fa9f5f40c38695327a92cb26 Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 17 Jan 2024 19:23:17 +0100 Subject: [PATCH 11/13] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 4c1d6432..64b872b2 100644 --- a/readme.md +++ b/readme.md @@ -46,7 +46,7 @@ services: Via `docker run` ```bash -docker run -it --rm -e "DISPLAY=vnc" -e "BOOT=http://example.com/image.iso" -p 5900:5900 --device=/dev/kvm --cap-add NET_ADMIN qemux/qemu-docker +docker run -it --rm -e "BOOT=http://example.com/image.iso" -p 8006:8006 --device=/dev/kvm --cap-add NET_ADMIN qemux/qemu-docker ``` ## FAQ From 8b480a0ac952119c9aea41e951fe73d5d889e7d8 Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 17 Jan 2024 19:24:40 +0100 Subject: [PATCH 12/13] Update docker-compose.yml --- docker-compose.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 44c5aee3..3ca3fb62 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: "3" services: qemu: container_name: qemu - image: qemux/qemu-docker:latest + image: qemux/qemu-docker environment: RAM_SIZE: "1G" CPU_CORES: "1" @@ -15,8 +15,6 @@ services: cap_add: - NET_ADMIN ports: - - 2222:22 - - 5900:5900 - - 8006:8006 + - 8006:8006 stop_grace_period: 2m restart: unless-stopped From 68480f97c0a0a57fdead9c72575bb0c0e5b1c844 Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 17 Jan 2024 19:37:14 +0100 Subject: [PATCH 13/13] feat: Custom VGA setting --- src/display.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/display.sh b/src/display.sh index 8f110ae1..6c2fc6c0 100644 --- a/src/display.sh +++ b/src/display.sh @@ -3,18 +3,22 @@ set -Eeuo pipefail # Docker environment variables -: "${GPU:="N"}" # GPU passthrough +: "${GPU:="N"}" # GPU passthrough +: "${VGA:="virtio"}" # VGA adaptor : "${DISPLAY:="web"}" # Display type case "${DISPLAY,,}" in vnc) - DISPLAY_OPTS="-display vnc=:0 -vga virtio" + DISPLAY_OPTS="-display vnc=:0 -vga $VGA" ;; web) - DISPLAY_OPTS="-display vnc=:0,websocket=5700 -vga virtio" + DISPLAY_OPTS="-display vnc=:0,websocket=5700 -vga $VGA" ;; + none) + DISPLAY_OPTS="-display none -vga none" + ;; *) - DISPLAY_OPTS="-display $DISPLAY -vga none" + DISPLAY_OPTS="-display $DISPLAY -vga $VGA" ;; esac @@ -22,7 +26,8 @@ if [[ "$GPU" != [Yy1]* ]] || [[ "$ARCH" != "amd64" ]]; then return 0 fi -DISPLAY_OPTS="-display egl-headless,rendernode=/dev/dri/renderD128 -vga virtio" +DISPLAY_OPTS="-display egl-headless,rendernode=/dev/dri/renderD128 -vga $VGA" + [[ "${DISPLAY,,}" == "vnc" ]] && DISPLAY_OPTS="$DISPLAY_OPTS -vnc :0" [[ "${DISPLAY,,}" == "web" ]] && DISPLAY_OPTS="$DISPLAY_OPTS -vnc :0,websocket=5700"