Skip to content

Windows Docker Desktop Powershell Skript #3719

@lh01-lft

Description

@lh01-lft

Is your feature request related to a problem? Please describe.
Yes - if you want to deploy dockerized version on windows Docker Desktop and you use powershell like me, you can't execute .sh files.

So this is just the sh file converted to ps1

Describe the solution you'd like
I will provide the solution + a wiki entry to edit in:
https://github.com/MrNeRF/LichtFeld-Studio/wiki/Build-instructions-%E2%80%90-Docker

Describe alternatives you've considered
Ubuntu wsl - but just noisy to install docker twice on the system

Additional context
ready to use Powershell plus wiki edit if you consider building this in.

ps1 File: .\docker\run_docker.ps1:

param(
    [switch]$b,
    [switch]$n,
    [switch]$u,
    [switch]$c,
    [switch]$h,
    [string]$CUDA_VERSION
)

function Show-Usage {
    Write-Host "Usage: .\run_docker.ps1 [-bnu] [-c] [CUDA_VERSION]"
    Write-Host "  -b       Build with cache"
    Write-Host "  -n       Build without cache"
    Write-Host "  -u       Start docker-compose and enter container"
    Write-Host "  -c       Stop and clean up"
    Write-Host "  -h       Show this help message"
    Write-Host ""
    Write-Host "If a CUDA version is passed (e.g. 12.8.0), it overrides auto-detection."
}

# --- Show help
if ($h) {
    Show-Usage
    exit 0
}

# --- Detect CUDA version (via nvcc)
if (-not $CUDA_VERSION) {
    try {
        $detected = & nvcc --version 2>$null | Select-String -Pattern 'release ([0-9]+\.[0-9]+)' | ForEach-Object {
            $_.Matches.Groups[1].Value
        } | Select-Object -First 1
        if ($detected) {
            $CUDA_VERSION = "$detected.0"
        } else {
            $CUDA_VERSION = "12.8.0"
        }
    } catch {
        $CUDA_VERSION = "12.8.0"
    }
}

Write-Host "Using CUDA version: $CUDA_VERSION"

# --- Define paths and flags
$COMPOSE_FILE = "docker/docker-compose.yml"
$BUILD = $false
$BUILD_ARGS = ""
$COMPOSEUP = $false

if ($b) {
    $BUILD = $true
}
if ($n) {
    $BUILD = $true
    $BUILD_ARGS = "--no-cache"
}
if ($u) {
    $COMPOSEUP = $true
}
if ($c) {
    Write-Host "Stopping and cleaning containers..."
    docker compose -f $COMPOSE_FILE down --remove-orphans
    exit 0
}

# --- Export environment variables for docker-compose
$env:USER_UID = (id -u 2>$null)
$env:USER_GID = (id -g 2>$null)
$env:USERNAME = $env:USERNAME
$env:USER_PASSWORD = $env:USERNAME
$env:HOSTNAME = $env:COMPUTERNAME
$env:HOME = $env:USERPROFILE
$env:CUDA_VERSION = $CUDA_VERSION

# --- Build docker image
if ($BUILD) {
    Write-Host "Building docker image with CUDA $CUDA_VERSION..."
    $env:DOCKER_BUILDKIT = "1"
    docker compose -f $COMPOSE_FILE build $BUILD_ARGS
    if ($LASTEXITCODE -ne 0) {
        Write-Host "Docker build failed!" -ForegroundColor Red
        exit 1
    }
}

# --- Start container
if ($COMPOSEUP) {
    Write-Host "Starting docker container..."
    docker compose -f $COMPOSE_FILE up -d
    if ($LASTEXITCODE -ne 0) {
        Write-Host "Docker compose up failed!" -ForegroundColor Red
        exit 1
    }
    docker compose -f $COMPOSE_FILE exec gs-cuda bash
}

Instructions:

# Build and start container
.\docker\run_docker.ps1 -b -u 12.8.0

# Build without cache
.\docker\run_docker.ps1 -n

# Stop containers
.\docker\run_docker.ps1 -c

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions