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 #!/bin/bash
# Docker Compose Windows VM Launcher for Omarchy # Docker Compose Windows VM Launcher for Omarchy
# Starts Windows VM via Docker and connects with RDP # Starts Windows VM via Docker Compose and connects with RDP
# When RDP closes, docker-compose will also stop # When RDP closes, docker-compose will stop
set -e 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" 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..." echo "Starting Windows VM..."
# Create Windows storage directory if it doesn't exist # Create Windows storage directory if it doesn't exist
mkdir -p "$WINDOWS_STORAGE_DIR" mkdir -p "$HOME/.windows"
# Check for required dependencies # Change to compose directory where docker-compose.yml is located
for cmd in docker rdesktop nc curl; do cd "$COMPOSE_DIR" || {
if ! command -v "$cmd" >/dev/null 2>&1; then echo "Error: Could not change to $COMPOSE_DIR"
echo "Error: Required command '$cmd' not found."
echo "Please ensure Docker, rdesktop, and netcat are installed."
exit 1 exit 1
fi }
done
# Function to handle cleanup # Function to handle cleanup
cleanup() { cleanup() {
echo "Shutting down Windows VM..." echo "Shutting down Windows VM..."
docker stop windows 2>/dev/null || true docker-compose down
docker rm windows 2>/dev/null || true
exit 0 exit 0
} }
# Set up signal handlers # Set up signal handlers
trap cleanup SIGTERM SIGINT trap cleanup SIGTERM SIGINT
# Check if container already exists and remove it # Start docker-compose in background
if docker ps -a --format '{{.Names}}' | grep -q "^windows$"; then docker-compose up &
echo "Removing existing Windows container..." COMPOSE_PID=$!
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
# Wait for container to be running # Wait for container to be running
echo "Waiting for Windows container to start..." echo "Waiting for Windows container to start..."
@@ -57,9 +47,9 @@ while true; do
echo " Container status: $CONTAINER_STATUS" echo " Container status: $CONTAINER_STATUS"
sleep 2 sleep 2
# Check if container is still running # Check if docker-compose process is still running
if ! docker ps --format '{{.Names}}' | grep -q "^windows$"; then if ! kill -0 $COMPOSE_PID 2>/dev/null; then
echo "Docker container died unexpectedly" echo "Docker Compose process died unexpectedly"
exit 1 exit 1
fi fi
done done

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