Skip to content

Instantly share code, notes, and snippets.

@Fartomy
Last active March 17, 2024 23:23
Show Gist options
  • Save Fartomy/63f32ee7b77911021e620ce1a1d2875f to your computer and use it in GitHub Desktop.
Save Fartomy/63f32ee7b77911021e620ce1a1d2875f to your computer and use it in GitHub Desktop.
Incy-wincy Windows in a container

🤏 Incy-wincy Windows Inside a Container

Any Windows version running in a Docker container!

Requirements

  1. Unix/Linux System
  2. KVM
  3. Docker

Windows can run on the docker container thanks to KVM. It can do this thanks to the --device=/dev/kvm parameter it gives to the docker container. This parameter allows the container to access the KVM device on the host machine. That's why we need to install KVM on the machine first.

This gist is based on Linux.

KVM Installation and Config

# 1. sudo apt update && sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virt-manager -y
# 2. usermod -aG libvirt $(whoami)
# 3. sudo systemctl start libvirtd
# 4. sudo systemctl enable libvirtd
# 5. sudo modprobe kvm
# 6. sudo nano /etc/modules
#
# To have KVM automatically installed at startup, edit the /etc/modules file and type "kvm" and
# add "kvm_intel" or "kvm_amd" modules:
#
# The contents of the file should look like this:
#
#     """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
#     # /etc/modules: kernel modules to load at boot time.
#     #
#     # This file contains the names of kernel modules that should be loaded
#     # at boot time, one per line. Lines beginning with "#" are ignored.
#
#     kvm
#     kvm_intel
#     kvm_amd
#     """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
#
# Use the following command to check that KVM is started:
#
# 7. lsmod | grep kvm
#
# Check the "/dev/kvm" directory should have been created.

Then, run the docker command:

docker run -it --rm --name windows -p 8006:8006 --device=/dev/kvm --cap-add NET_ADMIN --stop-timeout 120 dockurr/windows

RDP Instead of noVNC

Since noVNC is bulky and there is no sound. After the system is installed, we can install RDP from the microsoft store and use the IP in the URL to which we connected with noVNC, that is, the system's own IP. After installing RDP, we can connect to ourselves and get faster performance. It might also be a good idea to increase some CPU, RAM, and storage space before doing this.

version: "3"
services:
  windows:
    image: dockurr/windows
    container_name: windows
    devices:
      - /dev/kvm
    cap_add:
      - NET_ADMIN
    ports:
      - 8006:8006
      - 3389:3389/tcp
      - 3389:3389/udp
    stop_grace_period: 2m
    restart: on-failure
    environment:
      RAM_SIZE: "5G"
      CPU_CORES: 3
      DISK_SIZE: "100G"
      VERSION: "win11"

Finally, the Windows version can be changed by selecting the appropriate version from the table on the relevant github page and clicking VERSION in the environment section of the docker compose file.

Source

  1. Windows-docker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment