microsoft / navcontainerhelper

Official Microsoft repository for BcContainerHelper, a PowerShell module, which makes it easier to work with Business Central Containers on Docker.
MIT License
382 stars 244 forks source link

New-BCContainer: hcsshim::ImportLayer failed in Win32: The system cannot find the path specified. (0x3) #3443

Closed 4ampro closed 6 months ago

4ampro commented 6 months ago

Describe the issue Running New-BCContainer without specifying the license after reinstalling BcContainerHelper, per Freddydk

Scripts used to create container and cause the issue

$imageName = 'mcr.microsoft.com/businesscentral/sandbox:us'
$artifactUrl = Get-BcArtifactUrl -type sandbox -country us -select latest
$ContainerName = 'f01' # should be the same as the ServerName in launch.json for the test app
$UserName = 'admin'
$Password = ConvertTo-SecureString '[redacted]' -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ($UserName, $Password)
$Outdated = 'Y'

New-BCContainer `
-accept_eula `
-containerName $ContainerName `
-artifactUrl $artifactUrl `
-alwayspull `
-auth NavUserPassword `
-updateHosts `
-Credential $Credential `
-accept_outdated $Outdated `
-includeTestToolkit `
-isolation hyperv

Full output of scripts

PS C:\WINDOWS\system32> X:\Documents\Nav stuff\Docker\bc02\FreddyTest.ps1
BcContainerHelper is version 6.0.11
BcContainerHelper is running as administrator
HyperV is Enabled
UsePsSession is True
Host is Microsoft Windows 10 Pro - 10.0.19045.4170
Docker Client Version is 25.0.3
Docker Server Version is 25.0.3
Removing Desktop shortcuts
Downloading artifact /sandbox/23.5.16502.17828/us
Downloading C:\Users\UserName\AppData\Local\Temp\651a60b6-1904-4bf7-b9cf-bb885d1733a9.zip
Downloading using WebClient
Unpacking artifact to tmp folder using 7zip
Downloading platform artifact /sandbox/23.5.16502.17828/platform
Downloading C:\Users\UserName\AppData\Local\Temp\915f4757-ba67-4421-b6a9-485e94aada71.zip
Downloading using WebClient
Unpacking artifact to tmp folder using 7zip
Downloading Prerequisite Components
Downloading c:\bcartifacts.cache\sandbox\23.5.16502.17828\platform\Prerequisite Components\IIS URL Rewrite Module\rewrite_2.0_rtw_x64.msi
Downloading using WebClient
Downloading c:\bcartifacts.cache\sandbox\23.5.16502.17828\platform\Prerequisite Components\DotNetCore\DotNetCore.1.0.4_1.1.1-WindowsHosting.exe
Downloading using WebClient
Fetching all docker images
Fetching all docker volumes
ArtifactUrl and ImageName specified
Building multitenant image y:sandbox-23.5.16502.17828-us-mt based on mcr.microsoft.com/businesscentral:ltsc2019 with https://bcartifacts.azureedge.net/sandbox/23
.5.16502.17828/us
Pulling latest image mcr.microsoft.com/businesscentral:ltsc2019
ltsc2019: Pulling from businesscentral
Digest: sha256:ca49064a275b9e95c8d3a0ae8264a4222cd7597a84dd6d007276151cfe6bebfa
Status: Image is up to date for mcr.microsoft.com/businesscentral:ltsc2019
mcr.microsoft.com/businesscentral:ltsc2019
Generic Tag: 1.0.2.17
Container OS Version: 10.0.17763.5576 (ltsc2019)
Host OS Version: 10.0.19045.4170 (22H2)
Using hyperv isolation
Files in c:\bcartifacts.cache\tzp00k4r.zbh\my:
Copying Platform Artifacts
c:\bcartifacts.cache\sandbox\23.5.16502.17828\platform
Copying Database
Copying Licensefile
Copying ConfigurationPackages
C:\bcartifacts.cache\sandbox\23.5.16502.17828\us\ConfigurationPackages
Copying Extensions
C:\bcartifacts.cache\sandbox\23.5.16502.17828\us\Extensions
Copying Applications.US
C:\bcartifacts.cache\sandbox\23.5.16502.17828\us\Applications.US
c:\bcartifacts.cache\tzp00k4r.zbh
Sending build context to Docker daemon  2.589GB

Step 1/6 : FROM mcr.microsoft.com/businesscentral:ltsc2019
 ---> 64568c89e98d
Step 2/6 : ENV DatabaseServer=localhost DatabaseInstance=SQLEXPRESS DatabaseName=CRONUS IsBcSandbox=Y artifactUrl=https://bcartifacts.azureedge.net/sandbox/23.5.
16502.17828/us filesOnly=False
 ---> Running in 3681f4c4a208
 ---> Removed intermediate container 3681f4c4a208
 ---> 13eedd5a940c
Step 3/6 : COPY my /run/
 ---> 0912c1894dae
Step 4/6 : COPY NAVDVD /NAVDVD/
 ---> 861344e8a85c
Step 5/6 : RUN \Run\start.ps1 -installOnly -multitenant -includeTestToolkit
 ---> Running in 3d688926c4d8
c:\run\my folder doesn't exist, creating it
Using DVD installer from C:\Run\210-new
Installing Business Central: multitenant=True, installOnly=True, filesOnly=False, includeTestToolkit=True, includeTestLibrariesOnly=False, includeTestFrameworkOn
ly=False, includePerformanceToolkit=False, appArtifactPath=, platformArtifactPath=, databasePath=, licenseFilePath=, rebootContainer=False
Installing from DVD
Starting Local SQL Server
WARNING: Waiting for service 'SQL Server (SQLEXPRESS) (MSSQL$SQLEXPRESS)' to 
start...
Starting Internet Information Server
Copying Service Tier Files
C:\NAVDVD\ServiceTier\Program Files
C:\NAVDVD\ServiceTier\System64Folder
Copying PowerShell Scripts
C:\NAVDVD\WindowsPowerShellScripts\Cloud\NAVAdministration
C:\NAVDVD\WindowsPowerShellScripts\WebSearch
Copying Web Client Files
C:\NAVDVD\WebClient\Microsoft Dynamics NAV
Copying ModernDev Files
C:\NAVDVD
C:\NAVDVD\ModernDev\program files\Microsoft Dynamics NAV
Copying additional files
Copying ConfigurationPackages
C:\NAVDVD\ConfigurationPackages
Copying Test Assemblies
C:\NAVDVD\Test Assemblies
Copying Extensions
C:\NAVDVD\Extensions
Copying Applications
C:\NAVDVD\Applications
Copying Applications.US
C:\NAVDVD\Applications.US
Copying dependencies
Copying ReportBuilder
Importing PowerShell Modules
Restoring CRONUS Demo Database
Setting CompatibilityLevel for tenant on localhost\SQLEXPRESS
Exporting Application to CRONUS
Removing Application from tenant
Modifying Business Central Service Tier Config File for Docker
Creating Business Central Service Tier
Installing SIP crypto provider: 'C:\Windows\System32\NavSip.dll'
Starting Business Central Service Tier
Importing CRONUS license file
Copying Database on localhost\SQLEXPRESS from tenant to default
Taking database tenant offline
Copying database files
Attaching files as new Database default
Putting database tenant back online
Mounting tenant database
Mounting Database for default on server localhost\SQLEXPRESS with AllowAppDatabaseWrite = False
Sync'ing Tenant
Tenant is Operational
Permissions Mock is already published
Synchronizing Permissions Mock
Installing Permissions Mock
Test Runner is already published
Synchronizing Test Runner
Installing Test Runner
Any is already published
Synchronizing Any
Installing Any
Library Assert is already published
Synchronizing Library Assert
Installing Library Assert
Skipping Permissions Mock as it is already installed
Library Variable Storage is already published
Synchronizing Library Variable Storage
Installing Library Variable Storage
Publishing C:\Applications.US\Microsoft_System Application Test Library_23.5.16502.17828.app
Synchronizing System Application Test Library
Installing System Application Test Library
Publishing C:\Applications.US\Microsoft_Tests-TestLibraries_23.5.16502.17828.app
Synchronizing Tests-TestLibraries
Installing Tests-TestLibraries
Publishing C:\Applications\system application\test\Microsoft_System Application Test.app
Synchronizing System Application Test
Installing System Application Test
Publishing C:\Applications.US\Microsoft_Tests-Bank_23.5.16502.17828.app
Synchronizing Tests-Bank
Installing Tests-Bank
Publishing C:\Applications.US\Microsoft_Tests-Cash Flow_23.5.16502.17828.app
Synchronizing Tests-Cash Flow
Installing Tests-Cash Flow
Publishing C:\Applications.US\Microsoft_Tests-Cost Accounting_23.5.16502.17828.app
Synchronizing Tests-Cost Accounting
Installing Tests-Cost Accounting
Publishing C:\Applications.US\Microsoft_Tests-CRM integration_23.5.16502.17828.app
Synchronizing Tests-CRM integration
Installing Tests-CRM integration
Publishing C:\Applications.US\Microsoft_Tests-Data Exchange_23.5.16502.17828.app
Synchronizing Tests-Data Exchange
Installing Tests-Data Exchange
Publishing C:\Applications.US\Microsoft_Tests-Dimension_23.5.16502.17828.app
Synchronizing Tests-Dimension
Installing Tests-Dimension
Publishing C:\Applications.US\Microsoft_Tests-ERM_23.5.16502.17828.app
Synchronizing Tests-ERM
Installing Tests-ERM
Publishing C:\Applications.US\Microsoft_Tests-Fixed Asset_23.5.16502.17828.app
Synchronizing Tests-Fixed Asset
Installing Tests-Fixed Asset
Publishing C:\Applications.US\Microsoft_Tests-General Journal_23.5.16502.17828.app
Synchronizing Tests-General Journal
Installing Tests-General Journal
Publishing C:\Applications.US\Microsoft_Tests-Graph_23.5.16502.17828.app
Synchronizing Tests-Graph
Installing Tests-Graph
Publishing C:\Applications.US\Microsoft_Tests-Integration_23.5.16502.17828.app
Synchronizing Tests-Integration
Installing Tests-Integration
Publishing C:\Applications.US\Microsoft_Tests-Invoicing_23.5.16502.17828.app
Synchronizing Tests-Invoicing
Installing Tests-Invoicing
Publishing C:\Applications.US\Microsoft_Tests-Job_23.5.16502.17828.app
Synchronizing Tests-Job
Installing Tests-Job
Publishing C:\Applications.US\Microsoft_Tests-Local_23.5.16502.17828.app
Synchronizing Tests-Local
Installing Tests-Local
Publishing C:\Applications.US\Microsoft_Tests-Marketing_23.5.16502.17828.app
Synchronizing Tests-Marketing
Installing Tests-Marketing
Publishing C:\Applications.US\Microsoft_Tests-Misc_23.5.16502.17828.app
Synchronizing Tests-Misc
Installing Tests-Misc
Publishing C:\Applications.US\Microsoft_Tests-Monitor Sensitive Fields_23.5.16502.17828.app
Synchronizing Tests-Monitor Sensitive Fields
Installing Tests-Monitor Sensitive Fields
Publishing C:\Applications.US\Microsoft_Tests-Permissions_23.5.16502.17828.app
Synchronizing Tests-Permissions
Installing Tests-Permissions
Publishing C:\Applications.US\Microsoft_Tests-Physical Inventory_23.5.16502.17828.app
Synchronizing Tests-Physical Inventory
Installing Tests-Physical Inventory
Publishing C:\Applications.US\Microsoft_Tests-Prepayment_23.5.16502.17828.app
Synchronizing Tests-Prepayment
Installing Tests-Prepayment
Publishing C:\Applications.US\Microsoft_Tests-Rapid Start_23.5.16502.17828.app
Synchronizing Tests-Rapid Start
Installing Tests-Rapid Start
Publishing C:\Applications.US\Microsoft_Tests-Report_23.5.16502.17828.app
Synchronizing Tests-Report
Installing Tests-Report
Publishing C:\Applications.US\Microsoft_Tests-Resource_23.5.16502.17828.app
Synchronizing Tests-Resource
Installing Tests-Resource
Publishing C:\Applications.US\Microsoft_Tests-Reverse_23.5.16502.17828.app
Synchronizing Tests-Reverse
Installing Tests-Reverse
Publishing C:\Applications.US\Microsoft_Tests-SCM_23.5.16502.17828.app
Synchronizing Tests-SCM
Installing Tests-SCM
Publishing C:\Applications.US\Microsoft_Tests-SMB_23.5.16502.17828.app
Synchronizing Tests-SMB
Installing Tests-SMB
Publishing C:\Applications.US\Microsoft_Tests-Upgrade_23.5.16502.17828.app
Synchronizing Tests-Upgrade
Installing Tests-Upgrade
Publishing C:\Applications.US\Microsoft_Tests-User_23.5.16502.17828.app
Synchronizing Tests-User
Installing Tests-User
Publishing C:\Applications.US\Microsoft_Tests-VAT_23.5.16502.17828.app
Synchronizing Tests-VAT
Installing Tests-VAT
Publishing C:\Applications.US\Microsoft_Tests-Workflow_23.5.16502.17828.app
Synchronizing Tests-Workflow
Installing Tests-Workflow
Stopping Business Central Service Tier
Installation took 830 seconds
Installation complete
New-Bcimage Telemetry Correlation Id: ad4427ae-0419-4628-ae32-ba978e4e3929
New-BCContainer Telemetry Correlation Id: 8d6f8efd-4d1d-43b1-a962-7eb1dbafb8e8
DockerDo : re-exec error: exit status 1: output: hcsshim::ImportLayer failed in Win32: The system cannot find the path specified. (0x3)
ExitCode: 1
Commandline: docker build --isolation=hyperv --memory 8G --no-cache --tag y:sandbox-23.5.16502.17828-us-mt c:\bcartifacts.cache\tzp00k4r.zbh
At C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.11\ContainerHandling\New-NavImage.ps1:711 char:27
+ ...       if (!(DockerDo -command build -parameters @("--isolation=$isola ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,DockerDo

PS C:\WINDOWS\system32> docker version
Client:
 Cloud integration: v1.0.35+desktop.11
 Version:           25.0.3
 API version:       1.44
 Go version:        go1.21.6
 Git commit:        4debf41
 Built:             Tue Feb  6 21:13:02 2024
 OS/Arch:           windows/amd64
 Context:           default

Server: Docker Desktop 4.28.0 (139021)
 Engine:
  Version:          25.0.3
  API version:      1.44 (minimum version 1.24)
  Go version:       go1.21.6
  Git commit:       f417435
  Built:            Tue Feb  6 20:55:49 2024
  OS/Arch:          windows/amd64
  Experimental:     false
...

Additional context

freddydk commented 6 months ago

This error is typically caused by a faulty docker installation/file system (can be caused by many things - maybe the errors you had earlier). But... - it looks like the license error is gone. I usually use this mechanism https://freddysblog.com/2018/12/11/clean-up-after-yourself-docker-your-mom-isnt-here/ to cleanup my docker file system.

4ampro commented 6 months ago

I just completely uninstalled then installed docker prior to running any of these scripts. 'Docker Services not running' message sometimes pops up no matter how may times I uninstall it or install it.

Strange.

freddydk commented 6 months ago

Uninstalling docker might not cleanup a faulty file system.

freddydk commented 6 months ago

what docker version are you running? (docker desktop, mirantis, docker engine?)

4ampro commented 6 months ago

PS C:\WINDOWS\system32> docker version Client: Cloud integration: v1.0.35+desktop.11 Version: 25.0.3 API version: 1.44 Go version: go1.21.6 Git commit: 4debf41 Built: Tue Feb 6 21:13:02 2024 OS/Arch: windows/amd64 Context: default

Server: Docker Desktop 4.28.0 (139021) Engine: Version: 25.0.3 API version: 1.44 (minimum version 1.24) Go version: go1.21.6 Git commit: f417435 Built: Tue Feb 6 20:55:49 2024 OS/Arch: windows/amd64 Experimental: false

freddydk commented 6 months ago

I think there is a later docker desktop version - I seem to remember a problem with one of the prior versions - maybe that is what you have. I personally use Docker Engine (using this script to install and update https://github.com/microsoft/nav-arm-templates/blob/master/InstallOrUpdateDockerEngine.ps1)

4ampro commented 6 months ago

Gotcha but am I wrong to download 'docker' from the docker site?

freddydk commented 6 months ago

Docker Desktop is fine - 4.27.x just had some errors, which should be fixed in 4.28.0 The cleanup tool works with both - you can try that if you like.

4ampro commented 6 months ago

I was on 4.28.0.

Just ran your InstallOrUpdateDockerEngine script. Now running New-BCContainer.

Results in few minutes...

freddydk commented 6 months ago

You should probably run the cleanup script to cleanup the file system

4ampro commented 6 months ago

this? CleanupAfterDocker.ps1 If so, I'll stop my New-BCContainer, and run that one instead.

And btw, thanks for your help!

freddydk commented 6 months ago

yes - that one repairs the windowsfilter file system

4ampro commented 6 months ago

sweet.

running cleanupAfterDocker then New-BCContainer

4ampro commented 6 months ago

Says I'm not running Windows Containers which would be a problem but the Docker Icon seems to indicate I can switch to Linux which would mean I am running Windows Containers?

image

PS C:\WINDOWS\system32> X:\Documents\Nav stuff\Docker\bc02\Freddy CleanupAfterDocker.ps1
Checking Docker Service Settings...
Docker is not running Windows Containers
At X:\Documents\Nav stuff\Docker\bc02\Freddy CleanupAfterDocker.ps1:29 char:5
+     throw "Docker is not running Windows Containers"
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Docker is not running Windows Containers:String) [], RuntimeException
    + FullyQualifiedErrorId : Docker is not running Windows Containers
4ampro commented 6 months ago

It seems I am running windows?

PS C:\WINDOWS\system32> X:\Documents\Nav stuff\Docker\bc02\Freddy CleanupAfterDocker.ps1
Checking Docker Service Settings...
Docker is not running Windows Containers
At X:\Documents\Nav stuff\Docker\bc02\Freddy CleanupAfterDocker.ps1:29 char:5
+     throw "Docker is not running Windows Containers"
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Docker is not running Windows Containers:String) [], RuntimeException
    + FullyQualifiedErrorId : Docker is not running Windows Containers

PS C:\WINDOWS\system32> $dockerOsMode
 windows
4ampro commented 6 months ago

Docker returns lower case 'windows' and the script is looking for 'Windows' and seems it is case-sensitive.

$dockerInfo = (docker info)
$dockerOsMode = ($dockerInfo | Where-Object { $_.Trim().StartsWith('OSType: ') }).SubString(8)
if ($dockerOsMode -ne "Windows") {
    throw "Docker is not running Windows Containers"
}

PS C:\WINDOWS\system32> X:\Documents\Nav stuff\Docker\bc02\Freddy CleanupAfterDocker.ps1
Checking Docker Service Settings...
Docker is not running Windows Containers
At X:\Documents\Nav stuff\Docker\bc02\Freddy CleanupAfterDocker.ps1:29 char:5
+     throw "Docker is not running Windows Containers"
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Docker is not running Windows Containers:String) [], RuntimeException
    + FullyQualifiedErrorId : Docker is not running Windows Containers

PS C:\WINDOWS\system32> $dockerOsMode
 windows

Edit:

PS C:\WINDOWS\system32> docker info
Client:
 Version:    25.0.3
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.12.1-desktop.4
    Path:     C:\Program Files\Docker\cli-plugins\docker-buildx.exe
  compose: Docker Compose (Docker Inc.)
    Version:  v2.24.6-desktop.1
    Path:     C:\Program Files\Docker\cli-plugins\docker-compose.exe
  debug: Get a shell into any image or container. (Docker Inc.)
    Version:  0.0.24
    Path:     C:\Program Files\Docker\cli-plugins\docker-debug.exe
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-dev.exe
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.22
    Path:     C:\Program Files\Docker\cli-plugins\docker-extension.exe
  feedback: Provide feedback, right in your terminal! (Docker Inc.)
    Version:  v1.0.4
    Path:     C:\Program Files\Docker\cli-plugins\docker-feedback.exe
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v1.0.1
    Path:     C:\Program Files\Docker\cli-plugins\docker-init.exe
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-sbom.exe
  scout: Docker Scout (Docker Inc.)
    Version:  v1.5.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-scout.exe

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 25.0.3
 Storage Driver: windowsfilter
  Windows: 
 Logging Driver: json-file
 Plugins:
  Volume: local
  Network: ics internal l2bridge l2tunnel nat null overlay private transparent
  Log: awslogs etwlogs fluentd gcplogs gelf json-file local splunk syslog
 Swarm: inactive
 Default Isolation: hyperv
 Kernel Version: 10.0 19045 (19041.1.amd64fre.vb_release.191206-1406)
 Operating System: Microsoft Windows Version 22H2 (OS Build 19045.4170)
 OSType: windows
 Architecture: x86_64
 CPUs: 4
 Total Memory: 15.91GiB
 Name: navDev
 ID: 703db57e-f0cf-435d-93e4-6f5bca5679e2
 Docker Root Dir: C:\ProgramData\Docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
 Product License: Community Engine
freddydk commented 6 months ago

PowerShell -ne operator is case insensitive. There does however seem to be a space in front of the Windows. The line should be

$dockerOsMode = ($dockerInfo | Where-Object { $_.Trim().StartsWith('OSType: ') }).Trim().SubString(8)
freddydk commented 6 months ago

Which is updated here https://github.com/microsoft/nav-arm-templates/blob/master/CleanupAfterDocker.ps1 - but apparently not in the blogpost (or where you took the script from)

4ampro commented 6 months ago

Freddy, thank you very much for helping me. I'm kind of a noob but doing as you recommend:

Which is updated here https://github.com/microsoft/nav-arm-templates/blob/master/CleanupAfterDocker.ps1 - but apparently not in the blogpost (or where you took the script from)

PS C:\WINDOWS\system32> X:\Documents\Nav stuff\Docker\bc02\Freddy CleanupAfterDocker.ps1
$ErrorActionPreference : The term '$ErrorActionPreference' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the 
spelling of the name, or if a path was included, verify that the path is correct and try again.
At X:\Documents\Nav stuff\Docker\bc02\Freddy CleanupAfterDocker.ps1:1 char:1
+ $ErrorActionPreference = "Stop"
+ ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: ($ErrorActionPreference:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : CommandNotFoundException
freddydk commented 6 months ago

I think you need to run

. "X:\Documents\Nav stuff\Docker\bc02\Freddy CleanupAfterDocker.ps1"

But maybe there is an encoding BOM in the file - or maybe the file needs to be unblocked by windows explorer

freddydk commented 6 months ago

I have updated the script in the block post as well

4ampro commented 6 months ago

So, I'll run 'CleanUpAfterDocker' from here: https://freddysblog.com/2018/12/11/clean-up-after-yourself-docker-your-mom-isnt-here/

Output

PS C:\WINDOWS\system32> X:\Documents\Nav stuff\Docker\bc02\Freddy CleanupAfterDocker.ps1
$ErrorActionPreference : The term '$ErrorActionPreference' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the 
spelling of the name, or if a path was included, verify that the path is correct and try again.
At X:\Documents\Nav stuff\Docker\bc02\Freddy CleanupAfterDocker.ps1:1 char:1
+ $ErrorActionPreference = "Stop"
+ ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: ($ErrorActionPreference:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : CommandNotFoundException

Full Script

$ErrorActionPreference = "Stop"
$WarningActionPreference = "Stop"

# Specify which images to download
$ImagesToDownload = @()

$bcContainerHelperFolder = "C:\ProgramData\BcContainerHelper"

$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if (!($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))) {
    throw "This script must run with administrator privileges"
}

Write-Host "Checking Docker Service Settings..."
$dockerService = (Get-Service docker -ErrorAction Ignore)
if (!($dockerService)) {
    throw "Docker Service not found / Docker is not installed"
}

if ($dockerService.Status -ne "Running") {
    throw "Docker Service is $($dockerService.Status) (Needs to be running)"
}

$dockerInfo = (docker info)
$dockerOsMode = ($dockerInfo | Where-Object { $_.Trim().StartsWith('OSType: ') }).Trim().SubString(8)
if ($dockerOsMode -ne "Windows") {
    throw "Docker is not running Windows Containers"
}

$dockerRootDir = ($dockerInfo | Where-Object { $_.Trim().StartsWith('Docker Root Dir: ') }).Trim().SubString(17)
if (!(Test-Path $dockerRootDir -PathType Container)) {
    throw "Folder $dockerRootDir does not exist"
}

Write-Host -Foregroundcolor Red "This function will remove all containers, remove all images and clear the folder $dockerRootDir"
Write-Host -Foregroundcolor Red "The function will also clear the contents of $bcContainerHelperFolder."
Write-Host -Foregroundcolor Red "Are you absolutely sure you want to do this? (This cannot be undone)"
Write-Host -ForegroundColor Red "Type Yes to continue:" -NoNewline
if ((Read-Host) -ne "Yes") {
    throw "Mission aborted"
}

Write-Host "Running Docker System Prune"
docker system prune -f

Write-Host "Removing all containers (forced)"
docker ps -a -q | % { docker rm $_ -f 2> NULL }

Write-Host "Stopping Docker Service"
stop-service docker

Write-Host "Downloading Docker-Ci-Zap"
$dockerCiZapExe = Join-Path $Env:TEMP "docker-ci-zap.exe"
Remove-Item $dockerCiZapExe -Force -ErrorAction Ignore
(New-Object System.Net.WebClient).DownloadFile("https://github.com/moby/docker-ci-zap/raw/master/docker-ci-zap.exe", $dockerCiZapExe)
Unblock-File -Path $dockerCiZapExe

Write-Host "Running Docker-Ci-Zap on $dockerRootDir"
Write-Host -ForegroundColor Yellow "Note: If this fails, please restart your computer and run this script again"
& $dockerCiZapExe -folder $dockerRootDir

Write-Host "Removing Docker-Ci-Zap"
Remove-Item $dockerCiZapExe

Write-Host "Starting Docker Service"
Start-Service docker

if (Test-Path $bcContainerHelperFolder -PathType Container) {
    Write-Host "Cleaning up $bcContainerHelperFolder"
    Get-ChildItem $bcContainerHelperFolder -Force | ForEach-Object { 
        Remove-Item $_.FullName -Recurse -force
    }
}

if ($ImagesToDownload) {
    Write-Host -ForegroundColor Green "Done cleaning up, pulling images for $os"

    $os = "ltsc2016"
    if ((Get-CimInstance win32_operatingsystem).BuildNumber -ge 17763) { $os = "ltsc2019" }

    # Download images needed
    $imagesToDownload | ForEach-Object {
        if ($_.EndsWith('-ltsc2016') -or $_.EndsWith('-1709') -or $_.EndsWith('-1803') -or $_.EndsWith('-ltsc2019') -or
            $_.EndsWith(':ltsc2016') -or $_.EndsWith(':1709') -or $_.EndsWith(':1803') -or $_.EndsWith(':ltsc2019')) {
            $imageName = $_
        } elseif ($_.Contains(':')) {
            $imageName = "$($_)-$os"
        } else {
            $imageName = "$($_):$os"
        }
        Write-Host "Pulling $imageName"
        docker pull $imageName
    }
}

image

freddydk commented 6 months ago

If you are saying that you cannot run these lines in PowerShell:

$ErrorActionPreference = "Stop"
$WarningActionPreference = "Stop"

Then I guess you cannot run anything - I don't know what went wrong there - sorry. These are setting the preference of what to do if something fails or gives a warning,

4ampro commented 6 months ago

$WarningActionPreference is type 'string' so "Stop" is valid. $ErrorActionPreference is type 'ActionPreference' and setting its value to "Stop" seems to be the issue? I could be completely on the wrong path - like I said, I'm a noob.

image

4ampro commented 6 months ago

So, I restarted my machine and it seems it may have allowed me to continue past the $ErrorActionPreference is not recognized issue. I'm going to type Yes to continue:

Full Output

PS C:\WINDOWS\system32> X:\Documents\Nav stuff\Docker\bc02\Freddy CleanupAfterDocker.ps1
$ErrorActionPreference : The term '$ErrorActionPreference' is not recognized 
as the name of a cmdlet, function, script file, or operable program. Check the 
spelling of the name, or if a path was included, verify that the path is 
correct and try again.
At X:\Documents\Nav stuff\Docker\bc02\Freddy CleanupAfterDocker.ps1:1 char:1
+ $ErrorActionPreference = "Stop"
+ ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: ($ErrorActionPreference:String) 
    [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Checking Docker Service Settings...
This function will remove all containers, remove all images and clear the folder
 C:\ProgramData\Docker
The function will also clear the contents of C:\ProgramData\BcContainerHelper.
Are you absolutely sure you want to do this? (This cannot be undone)
Type Yes to continue:Yes
Running Docker System Prune
Deleted Networks:
Default Switch

Total reclaimed space: 0B
Removing all containers (forced)
Stopping Docker Service
WARNING: Waiting for service 'Docker Engine (docker)' to stop...
WARNING: Waiting for service 'Docker Engine (docker)' to stop...
Downloading Docker-Ci-Zap
Running Docker-Ci-Zap on C:\ProgramData\Docker
Note: If this fails, please restart your computer and run this script again
INFO: Zapped successfully
Removing Docker-Ci-Zap
Starting Docker Service
Start-Service : Failed to start service 'Docker Engine (docker)'.
At X:\Documents\Nav stuff\Docker\bc02\Freddy CleanupAfterDocker.ps1:66 char:1
+ Start-Service docker
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (System.ServiceProcess.ServiceController:ServiceController) [Start-Service], ServiceCommandException
    + FullyQualifiedErrorId : StartServiceFailed,Microsoft.PowerShell.Commands.StartServiceCommand

Cleaning up C:\ProgramData\BcContainerHelper

PS C:\WINDOWS\system32> 
freddydk commented 6 months ago

What version of PowerShell are you running here?

$PSVersionTable tells you

4ampro commented 6 months ago
PS C:\WINDOWS\system32> $PSVersionTable 

Name                           Value                                                                          
----                           -----                                                                          
PSVersion                      5.1.19041.4170                                                                 
PSEdition                      Desktop                                                                        
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                        
BuildVersion                   10.0.19041.4170                                                                
CLRVersion                     4.0.30319.42000                                                                
WSManStackVersion              3.0                                                                            
PSRemotingProtocolVersion      2.3                                                                            
SerializationVersion           1.1.0.1 
freddydk commented 6 months ago

ISE (x86) or ISE?

4ampro commented 6 months ago

sorry i'm a dummy: there is no help | about, so the window text is 'Administrator: Windows PowerShell ISE'.

Presumably ISE?

freddydk commented 6 months ago

Yes. So,... $ErrorActionPreference = "Stop" is used all over. the variable is an enum - and it automatically converts strings to that - the fact that this isn't working doesn't give me much confidence in anything working. Sorry - you might need to find somebody who knows how to troubleshoot this or reinstall the machine.

4ampro commented 6 months ago

Understandable.

One quirky thing: $ErrorActionPreference = "Stop" runs by itself with no issues. image

When it runs in the script you provided, it fails. image

freddydk commented 6 months ago

and if you copy/paste the script into a new tab without saving it and using F5 to run it - it still fails?

I have seen a million different issues and problems with PowerShell - but this one is new.

What does the command Get-ExecutionPolicy return? Is the .ps1 file blocked in Windows Explorer?

4ampro commented 6 months ago

I just uninstalled then installed the latest of both docker and pse. I've been using Docker and Pse for the last few years with minor issues. This came from out of nowhere from what it seems but the ONLY use of these two apps is for New-BCContainer and BC-related stuff like updating licenses when they get renewed and some ancillary things like listing containers, but nothing major.

I reinstalled Docker (as admin) from the file on its web site. I reinstalled PSE from command line (as admin): winget install --id Microsoft.Powershell --source winget

Both are running as admin.

and if you copy/paste the script into a new tab without saving it and using F5 to run it - it still fails?


$ErrorActionPreference : The term '$ErrorActionPreference' is not recognized as the 
name of a cmdlet, function, script file, or operable program. Check the spelling of the 
name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ $ErrorActionPreference = "Stop"
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: ($ErrorActionPreference:String) [], Comma 
ndNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Checking Docker Service Settings... This function will remove all containers, remove all images and clear the folder C:\Progra mData\Docker The function will also clear the contents of C:\ProgramData\BcContainerHelper. Are you absolutely sure you want to do this? (This cannot be undone) Type Yes to continue:Yes Running Docker System Prune Deleted Networks: Default Switch

Total reclaimed space: 0B Removing all containers (forced) Stopping Docker Service WARNING: Waiting for service 'Docker Engine (docker)' to stop... WARNING: Waiting for service 'Docker Engine (docker)' to stop... Downloading Docker-Ci-Zap Running Docker-Ci-Zap on C:\ProgramData\Docker Note: If this fails, please restart your computer and run this script again INFO: Zapped successfully Removing Docker-Ci-Zap Starting Docker Service Start-Service : Failed to start service 'Docker Engine (docker)'. At line:66 char:1

Cleaning up C:\ProgramData\BcContainerHelper


> What does the command Get-ExecutionPolicy return?

PS C:\WINDOWS\system32> Get-ExecutionPolicy RemoteSigned


> Is the .ps1 file blocked in Windows Explorer?

No.
4ampro commented 6 months ago

I have seen a million different issues and problems with PowerShell - but this one is new.

How do I move this up the ladder if we cannot figure it out between us? Wiping my machine is not an option really.

4ampro commented 6 months ago

Anyhow, I downloaded my license again, specifying v21 and I'm back to basically another 'file not found' issue. Something is just not right and the non-cumulative error reporting that trickles out errors until the real cause is discovered is driving me to drink the Heinekens.

I've uninstalled, reinstalled, downloaded the latest, stood on one leg when the Worm Moon is full and all that jazz - even on a Monday. After working fine for years. Go figure?

DockerDo : re-exec error: exit status 1: output: hcsshim::ImportLayer failed in Win32: The system cannot find the path specified. (0x3)
ExitCode: 1
Commandline: docker build --isolation=hyperv --memory 8G --no-cache --tag y:sandbox-23.5.16502.17828-us-mt c:\bcartifacts.cache\cfuzy3jy.3cd
At C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.11\ContainerHandling\New-NavImage.ps1:711 char:27
+ ...       if (!(DockerDo -command build -parameters @("--isolation=$isola ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,DockerDo
freddydk commented 6 months ago

One thing I just saw... - remove the -accept_outdated line and try again.

New-BCContainer `
    -accept_eula `
    -containerName $ContainerName `
    -artifactUrl $artifactUrl `
    -alwayspull `
    -auth NavUserPassword `
    -updateHosts `
    -Credential $Credential `
    -includeTestToolkit `
    -isolation hyperv

You specified the value as it was a boolean - it isn't - it is a switch, meaning that the boolean value was presumed to be the value for imagename and subsequently, it tries to create an image. Without the line, it might work better.

4ampro commented 6 months ago

You did it. You crazy son of a bitch, you did it. That's some kung fu voodoo for sure!

Thanks for sticking with me all day. If I ever catch you at a conference, I you some cold beer for sure.

Really man, thank you so much for the 2nd eye. Running a one-man-show is really difficult and you were my partner in crime today.

freddydk commented 6 months ago

Thanks:-) In my Outlook, Copilot summarizes this thread like this:

image

Pretty nice