Last active
September 24, 2020 07:50
-
-
Save aadennis/ad08319e0b0ede13ba39beae7c7d7e8a to your computer and use it in GitHub Desktop.
Run a container from an image. If there is no image argument passed, select from a known set. See comments.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$imageSet = | |
"mcr.microsoft.com/windows/servercore:ltsc2016", | |
"mcr.microsoft.com/windows/servercore:ltsc2019", | |
"mcr.microsoft.com/windows/servercore:10.0.14393.3808" | |
function Run-Container($volumeShare, $image) { | |
if ($image -eq $null) { | |
Write-Host "No image passed in. Select from the following..." | |
$index = 0 | |
$imageSet | ForEach-Object { | |
$currentImage = $_ | |
$index++ | |
Write-Host "$($index): $currentImage" | |
} | |
$imageIndexToUse = Read-Host "Enter a number [1] to [$index]" | |
if ($imageIndexToUse -lt 1 -or $imageIndexToUse -gt $index) { | |
write-host "$imageIndexToUse is not a valid image index. Exiting..." | |
return | |
} | |
$image = $imageSet[$imageIndexToUse-1] | |
} | |
Write-Host "running container..." | |
Write-Host "volumeshare: $volumeShare" | |
Write-Host "image: $image" | |
docker run -v $volumeShare -it $image powershell | |
} | |
$volumeShare = "c:\HostShare:c:\ContainerShare" | |
$image = "mcr.microsoft.com/windows/servercore:ltsc2016" | |
# Run-Container -volumeShare $volumeShare -image $image | |
Run-Container -volumeShare $volumeShare |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment