updating to use docker-compose

This commit is contained in:
sspaeti
2025-09-15 19:56:31 +02:00
parent c45ad39a46
commit 764ad11e44
2 changed files with 40 additions and 29 deletions

View File

@@ -1,50 +1,40 @@
#!/bin/bash
# Docker Compose Windows VM Launcher for Omarchy
# Starts Windows VM via Docker and connects with RDP
# When RDP closes, docker-compose will also stop
# Starts Windows VM via Docker Compose and connects with RDP
# When RDP closes, docker-compose will stop
set -e
WINDOWS_STORAGE_DIR="$HOME/.windows"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
COMPOSE_DIR="$SCRIPT_DIR/../config/windows-vm"
RDP_COMMAND="rdesktop -g 1920x1200 -P -z -x l -r sound:off -u docker 127.0.0.1:3389 -p admin"
DOCKER_COMMAND="docker run -d --name windows -p 8006:8006 -p 3389:3389/tcp -p 3389:3389/udp --device=/dev/kvm --device=/dev/net/tun --cap-add NET_ADMIN -v ${WINDOWS_STORAGE_DIR}:/storage --stop-timeout 120 dockurr/windows"
echo "Starting Windows VM..."
# Create Windows storage directory if it doesn't exist
mkdir -p "$WINDOWS_STORAGE_DIR"
mkdir -p "$HOME/.windows"
# Change to compose directory where docker-compose.yml is located
cd "$COMPOSE_DIR" || {
echo "Error: Could not change to $COMPOSE_DIR"
exit 1
}
# Check for required dependencies
for cmd in docker rdesktop nc curl; do
if ! command -v "$cmd" >/dev/null 2>&1; then
echo "Error: Required command '$cmd' not found."
echo "Please ensure Docker, rdesktop, and netcat are installed."
exit 1
fi
done
# Function to handle cleanup
cleanup() {
echo "Shutting down Windows VM..."
docker stop windows 2>/dev/null || true
docker rm windows 2>/dev/null || true
docker-compose down
exit 0
}
# Set up signal handlers
trap cleanup SIGTERM SIGINT
# Check if container already exists and remove it
if docker ps -a --format '{{.Names}}' | grep -q "^windows$"; then
echo "Removing existing Windows container..."
docker stop windows 2>/dev/null || true
docker rm windows 2>/dev/null || true
fi
# Start docker container
echo "Starting Windows container..."
eval $DOCKER_COMMAND
# Start docker-compose in background
docker-compose up &
COMPOSE_PID=$!
# Wait for container to be running
echo "Waiting for Windows container to start..."
@@ -57,9 +47,9 @@ while true; do
echo " Container status: $CONTAINER_STATUS"
sleep 2
# Check if container is still running
if ! docker ps --format '{{.Names}}' | grep -q "^windows$"; then
echo "Docker container died unexpectedly"
# Check if docker-compose process is still running
if ! kill -0 $COMPOSE_PID 2>/dev/null; then
echo "Docker Compose process died unexpectedly"
exit 1
fi
done
@@ -97,4 +87,4 @@ echo "When you close RDP, the Windows VM will automatically shut down."
$RDP_COMMAND
# If RDP exits, cleanup
cleanup
cleanup

View File

@@ -0,0 +1,21 @@
services:
windows:
image: dockurr/windows
container_name: windows-omarchy
environment:
VERSION: "11"
RAM_SIZE: "12G"
CPU_CORES: "4"
devices:
- /dev/kvm
- /dev/net/tun
cap_add:
- NET_ADMIN
ports:
- 8006:8006
- 3389:3389/tcp
- 3389:3389/udp
volumes:
- ~/.windows:/storage
restart: always
stop_grace_period: 2m