Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| docs:guide-user:virtualization:docker_openwrt_image [2022/05/03 19:11] – [OpenWrt in QEMU in Docker] Add simple and advanced examples jwmullally | docs:guide-user:virtualization:docker_openwrt_image [2022/06/23 18:07] (current) – [OpenWrt in QEMU in Docker: Advanced Example] Simplify supplying custom config jwmullally | ||
|---|---|---|---|
| Line 318: | Line 318: | ||
| <code bash> | <code bash> | ||
| docker build . -t openwrt_in_qemu | docker build . -t openwrt_in_qemu | ||
| - | docker run --name my_openwrt -p 30022:30022,30080:30080 openwrt_in_qemu | + | docker run --name my_openwrt -p 30022: |
| </ | </ | ||
| Line 410: | Line 410: | ||
| This Docker image is similar to the above, with a few more features: | This Docker image is similar to the above, with a few more features: | ||
| - | * Support arbitrary container user IDs | + | |
| - | * Tunable QEMU configuration | + | * Tunable QEMU configuration |
| - | * A SPICE console + USB redirection | + | * A SPICE console + USB redirection |
| - | * KVM acceleration support | + | * KVM acceleration support |
| - | * Custom VM initialization scripts (e.g. from a Kubernetes ConfigMap) | + | * Custom VM initialization scripts (e.g. from a Kubernetes ConfigMap) |
| - | * Default admin firewall rules and disk resizing | + | * Default admin firewall rules and disk resizing |
| - | * Healthchecks | + | * Healthchecks |
| < | < | ||
| # syntax=docker/ | # syntax=docker/ | ||
| # | # | ||
| - | # This Dockerfile creates a container image running | + | # This Dockerfile creates a container image running |
| # https:// | # https:// | ||
| # This can be run on regular container clusters (e.g. Kubernetes, | # This can be run on regular container clusters (e.g. Kubernetes, | ||
| # without any special permissions. | # without any special permissions. | ||
| + | # | ||
| + | # | ||
| + | # | ||
| # | # | ||
| # For VGA console access and USB redirection, | # For VGA console access and USB redirection, | ||
| - | # on port 5900. | + | # (e.g. " |
| # | # | ||
| # To connect to the VM serial console, connect to the running container | # To connect to the VM serial console, connect to the running container | ||
| - | # and execute | + | # and execute |
| # | # | ||
| - | # | + | # |
| - | # | + | # |
| # | # | ||
| # To use KVM acceleration, | # To use KVM acceleration, | ||
| # | # | ||
| - | # | + | # |
| # | # | ||
| # Volumes: | # Volumes: | ||
| Line 446: | Line 449: | ||
| # / | # / | ||
| # You can use a shared volume/ | # You can use a shared volume/ | ||
| - | # | + | # |
| - | # VM on first boot. If " | + | # which you can use to provide other files. For testing, start docker |
| - | # the host container | + | # with "--volume / |
| - | # | + | # |
| - | # A default script " | + | # container.d: |
| - | # password, open admin ports and resize the disk. | + | # vm.d: Scripts run on the VM |
| - | FROM docker.io/ | + | FROM docker.io/ |
| # Install QEMU, remove large unnecessary files | # Install QEMU, remove large unnecessary files | ||
| Line 469: | Line 472: | ||
| rm -f / | rm -f / | ||
| - | # Download | + | # Download |
| ENV IMAGE_URL=" | ENV IMAGE_URL=" | ||
| ENV IMAGE_FILE=" | ENV IMAGE_FILE=" | ||
| Line 507: | Line 510: | ||
| chmod +x / | chmod +x / | ||
| - | # Write default VM configuration | + | # Create |
| + | RUN mkdir -p / | ||
| RUN echo -e '# | RUN echo -e '# | ||
| - | set -ex \n\ | + | set -e \n\ |
| - | cat << EOF\n\ | + | cat > vm.d/ |
| + | #!/bin/sh \n\ | ||
| + | set -e \n\ | ||
| + | uci set system.@system[0].hostname=" | ||
| + | uci commit system \n\ | ||
| + | EOF\n\ | ||
| + | chmod +x vm.d/ | ||
| + | \n\' > / | ||
| + | chmod +x / | ||
| + | |||
| + | RUN echo -e '# | ||
| + | set -e \n\ | ||
| + | cat > vm.d/ | ||
| #!/bin/sh \n\ | #!/bin/sh \n\ | ||
| set -e \n\ | set -e \n\ | ||
| echo -e " | echo -e " | ||
| - | set -x \n\ | + | EOF\n\ |
| + | chmod +x vm.d/20-password.sh \n\ | ||
| + | \n\' > / | ||
| + | chmod +x / | ||
| + | |||
| + | RUN echo -e '# | ||
| + | set -ex \n\ | ||
| uci add firewall rule \n\ | uci add firewall rule \n\ | ||
| uci set firewall.@rule[-1].name=" | uci set firewall.@rule[-1].name=" | ||
| Line 523: | Line 546: | ||
| uci set firewall.@rule[-1].target=" | uci set firewall.@rule[-1].target=" | ||
| uci commit firewall \n\ | uci commit firewall \n\ | ||
| + | \n\' > / | ||
| + | chmod +x / | ||
| + | |||
| + | RUN echo -e '# | ||
| + | set -ex \n\ | ||
| ubus wait_for network.interface.wan \n\ | ubus wait_for network.interface.wan \n\ | ||
| sleep 3 \n\ | sleep 3 \n\ | ||
| - | / | ||
| opkg update \n\ | opkg update \n\ | ||
| + | \n\' > / | ||
| + | chmod +x / | ||
| + | |||
| + | RUN echo -e '# | ||
| + | set -ex \n\ | ||
| opkg install partx-utils resize2fs sfdisk tune2fs \n\ | opkg install partx-utils resize2fs sfdisk tune2fs \n\ | ||
| echo "- +" | sfdisk --force -N 2 /dev/vda \n\ | echo "- +" | sfdisk --force -N 2 /dev/vda \n\ | ||
| Line 535: | Line 567: | ||
| mount -o remount,rw / \n\ | mount -o remount,rw / \n\ | ||
| resize2fs /dev/vda2 \n\ | resize2fs /dev/vda2 \n\ | ||
| - | EOF\n\ | + | \n\' > /usr/local/share/ |
| - | \n' > /usr/local/bin/gen-default-vm-config.sh && \ | + | chmod +x /usr/local/share/ |
| - | chmod +x /usr/local/bin/gen-default-vm-config.sh | + | |
| # Write VM configuration archive as serial console commands to STDOUT | # Write VM configuration archive as serial console commands to STDOUT | ||
| Line 552: | Line 583: | ||
| mkdir / | mkdir / | ||
| tar -zxvf / | tar -zxvf / | ||
| - | / | + | sleep 5 \n\ |
| + | (cd / | ||
| poweroff \n\ | poweroff \n\ | ||
| EOF\n\ | EOF\n\ | ||
| Line 561: | Line 593: | ||
| RUN echo -e '# | RUN echo -e '# | ||
| set -ex \n\ | set -ex \n\ | ||
| + | echo " | ||
| + | find / | ||
| + | sleep 5 \n\ | ||
| rm -rf / | rm -rf / | ||
| cp -rv / | cp -rv / | ||
| - | gen-default-vm-config.sh > / | + | mkdir -p / |
| - | chmod +x / | + | if [ -z " |
| - | if [ ! -f / | + | |
| - | | + | |
| - | (cd / | + | |
| - | | + | |
| - | mv /tmp/vmconfig/default-vm-config.sh / | + | |
| - | fi \n\ | + | |
| fi \n\ | fi \n\ | ||
| + | (cd / | ||
| run-vm.sh & \n\ | run-vm.sh & \n\ | ||
| QEMU_PID=" | QEMU_PID=" | ||
| Line 577: | Line 609: | ||
| socat STDOUT unix-connect:/ | socat STDOUT unix-connect:/ | ||
| serialize-vm-config.sh / | serialize-vm-config.sh / | ||
| - | VM_CONFIG_RESULT=" | + | VM_CONFIG_RESULT=" |
| if test " | if test " | ||
| exit 1 \n\ | exit 1 \n\ | ||
| Line 631: | Line 663: | ||
| provision-image.sh \n\ | provision-image.sh \n\ | ||
| if [ ! -f / | if [ ! -f / | ||
| - | timeout -s SIGINT " | + | timeout -s SIGINT " |
| touch / | touch / | ||
| chmod g+rw / | chmod g+rw / | ||
| Line 648: | Line 680: | ||
| ENV QEMU_PASSWORD=" | ENV QEMU_PASSWORD=" | ||
| ENV QEMU_CONFIG_TIMEOUT=" | ENV QEMU_CONFIG_TIMEOUT=" | ||
| + | ENV QEMU_CONFIG_NO_DEFAULTS="" | ||
| + | ENV QEMU_HOSTNAME=" | ||
| ENV QEMU_ARGS="" | ENV QEMU_ARGS="" | ||