feat: Automaticly set controlport

feat: Automaticly set controlport
This commit is contained in:
Kroese 2023-11-20 13:02:41 +01:00 committed by GitHub
commit 5028c9c6bf
6 changed files with 24 additions and 25 deletions

View file

@ -18,12 +18,7 @@ RUN apt-get update && apt-get -y upgrade && \
&& apt-get clean \ && apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Using a wildcard causes caching problems on some systems COPY ./src /run/
COPY src/disk.sh /run/
COPY src/display.sh /run/
COPY src/entry.sh /run/
COPY src/install.sh /run/
COPY src/network.sh /run/
RUN chmod +x /run/*.sh RUN chmod +x /run/*.sh
VOLUME /storage VOLUME /storage

View file

@ -4,12 +4,11 @@ services:
container_name: qemu container_name: qemu
image: qemux/qemu-docker:latest image: qemux/qemu-docker:latest
environment: environment:
DISPLAY: "vnc"
CPU_CORES: "1" CPU_CORES: "1"
RAM_SIZE: "512M" RAM_SIZE: "512M"
DISK_SIZE: "16G" DISK_SIZE: "16G"
BOOT: "https://dl-cdn.alpinelinux.org/alpine/v3.18/releases/x86_64/alpine-standard-3.18.2-x86_64.iso" BOOT: "https://dl-cdn.alpinelinux.org/alpine/v3.18/releases/x86_64/alpine-standard-3.18.2-x86_64.iso"
DISPLAY: "vnc"
CONTROL_PORTS: "5900"
devices: devices:
- /dev/kvm - /dev/kvm
- /dev/vhost-net - /dev/vhost-net
@ -18,7 +17,7 @@ services:
cap_add: cap_add:
- NET_ADMIN - NET_ADMIN
ports: ports:
- 22:22 - 2222:22
- 5900:5900 - 5900:5900
restart: on-failure restart: on-failure
stop_grace_period: 1m stop_grace_period: 1m

View file

@ -28,6 +28,7 @@ services:
container_name: qemu container_name: qemu
image: qemux/qemu-docker:latest image: qemux/qemu-docker:latest
environment: environment:
DISPLAY: "vnc"
DISK_SIZE: "16G" DISK_SIZE: "16G"
BOOT: "https://dl-cdn.alpinelinux.org/alpine/v3.18/releases/x86_64/alpine-standard-3.18.2-x86_64.iso" BOOT: "https://dl-cdn.alpinelinux.org/alpine/v3.18/releases/x86_64/alpine-standard-3.18.2-x86_64.iso"
devices: devices:
@ -35,7 +36,8 @@ services:
cap_add: cap_add:
- NET_ADMIN - NET_ADMIN
ports: ports:
- 22:22 - 2222:22
- 5900:5900
restart: on-failure restart: on-failure
``` ```
@ -124,8 +126,19 @@ docker run -it --rm -e "BOOT=http://www.example.com/image.iso" --device=/dev/kvm
``` ```
If you receive an error from `kvm-ok` indicating that KVM acceleration can't be used, check your BIOS settings. If you receive an error from `kvm-ok` indicating that KVM acceleration can't be used, check your BIOS settings.
* ### How can I connect with VNC?
To enable VNC, add the following lines to your compose file:
```yaml
environment:
DISPLAY: "vnc"
ports:
- 5900:5900
```
* ### How do I provide extra arguments to QEMU? * ### How do I provide custom arguments to QEMU?
You can create the `ARGUMENTS` environment variable to provide additional arguments to QEMU at runtime: You can create the `ARGUMENTS` environment variable to provide additional arguments to QEMU at runtime:
@ -187,17 +200,6 @@ docker run -it --rm -e "BOOT=http://www.example.com/image.iso" --device=/dev/kvm
Please note that even if you don't need DHCP, it's still recommended to enable this feature as it prevents NAT issues and increases performance by using a `macvtap` interface. Please note that even if you don't need DHCP, it's still recommended to enable this feature as it prevents NAT issues and increases performance by using a `macvtap` interface.
* ### How can I connect with VNC?
To enable VNC, add the following lines to your compose file:
```yaml
ports:
"5900:5900"
environment:
DISPLAY: "vnc"
```
[build_url]: https://github.com/qemu-tools/qemu-docker/ [build_url]: https://github.com/qemu-tools/qemu-docker/
[hub_url]: https://hub.docker.com/r/qemux/qemu-docker/ [hub_url]: https://hub.docker.com/r/qemux/qemu-docker/
[tag_url]: https://hub.docker.com/r/qemux/qemu-docker/tags [tag_url]: https://hub.docker.com/r/qemux/qemu-docker/tags

View file

@ -5,7 +5,7 @@ set -Eeuo pipefail
: ${DISPLAY:='none'} # Display type : ${DISPLAY:='none'} # Display type
case "$DISPLAY" in case "${DISPLAY,,}" in
vnc) vnc)
DISPLAY_OPTS="-nographic -vga std -vnc :0" DISPLAY_OPTS="-nographic -vga std -vnc :0"
;; ;;

View file

@ -33,8 +33,8 @@ cd /run
. install.sh # Get bootdisk . install.sh # Get bootdisk
. disk.sh # Initialize disks . disk.sh # Initialize disks
. network.sh # Initialize network
. display.sh # Initialize display . display.sh # Initialize display
. network.sh # Initialize network
KVM_ERR="" KVM_ERR=""
KVM_OPTS="" KVM_OPTS=""
@ -69,7 +69,6 @@ ARGS=$(echo "$ARGS" | sed 's/\t/ /g' | tr -s ' ')
trap - ERR trap - ERR
info "Booting image using ${VERS}..." info "Booting image using ${VERS}..."
[[ "${DEBUG}" == [Yy1]* ]] && set -x [[ "${DEBUG}" == [Yy1]* ]] && set -x
exec qemu-system-x86_64 ${ARGS:+ $ARGS} exec qemu-system-x86_64 ${ARGS:+ $ARGS}
{ set +x; } 2>/dev/null { set +x; } 2>/dev/null

View file

@ -148,6 +148,10 @@ configureNAT () {
ip link set dev "${VM_NET_TAP}" master dockerbridge ip link set dev "${VM_NET_TAP}" master dockerbridge
if [[ -z "${CONTROL_PORTS}" ]] && [[ "${DISPLAY,,}" == "vnc" ]]; then
CONTROL_PORTS='5900'
fi
CONTROL_PORT_ARGS='' CONTROL_PORT_ARGS=''
for PORT in $CONTROL_PORTS ; do for PORT in $CONTROL_PORTS ; do
CONTROL_PORT_ARGS="$CONTROL_PORT_ARGS ! --dport $PORT" CONTROL_PORT_ARGS="$CONTROL_PORT_ARGS ! --dport $PORT"