microsoft / navcontainerhelper

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

New-BcImage - failed in Win32: Incorrect function #1229

Closed SteinarHrafn closed 3 years ago

SteinarHrafn commented 4 years ago

Describe the issue New-BCImage fails on some, but not all, machines.

Scripts used to create container and cause the issue

Import-Module navcontainerhelper
$RequiredVersion = "16.4.14693.15445"
$Country = "w1"
$url = Get-BCArtifactUrl -type OnPrem -storageAccount bcartifacts -country $Country -version $RequiredVersion
New-BCImage -imageName "businesscentral:$RequiredVersion" -artifactUrl $url

Full output of scripts WARNING: The names of some imported commands from the module 'navcontainerhelper' include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command ag ain with the Verbose parameter. For a list of approved verbs, type Get-Verb. Pulling latest image mcr.microsoft.com/dynamicsnav:10.0.18363.1016-generic 10.0.18363.1016-generic: Pulling from dynamicsnav Generic Tag: 0.1.0.16 Container OS Version: 10.0.18363.1016 (1909) Host OS Version: 10.0.18363.1016 (1909) Copying Platform Artifacts Copying Database Copying Licensefile c:\bcartifacts.cache\tmp637333471315334094 Sending build context to Docker daemon 1.302GB

Step 1/6 : FROM mcr.microsoft.com/dynamicsnav:10.0.18363.1016-generic ---> ce98c3fa2cea Step 2/6 : ENV DatabaseServer=localhost DatabaseInstance=SQLEXPRESS DatabaseName=CRONUS IsBcSandbox=N artifactUrl=https://bcartifacts.azureedge.net/onprem/16.4.14693.15445/w1 ---> Running in 55e3e02fda5d docker : hcsshim::PrepareLayer - failed failed in Win32: Incorrect function. (0x1) At C:\Program Files\WindowsPowerShell\Modules\navcontainerhelper\0.7.0.25\ContainerHandling\New-NavImage.ps1:312 char:1

Additional context What we have tried so far:

freddydk commented 4 years ago

PrepareLayer is typically that something is wrong in docker and typically caused by a windows update or like. Normally I recommend people to do a factory reset of docker Desktop and re-run

SteinarHrafn commented 4 years ago

We have tried that on 2 different machines with no luck. We are in the process of doing complete re-install of docker now.

SteinarHrafn commented 4 years ago

Getting the same issue even after uninstall-install-restart.

freddydk commented 4 years ago

You say some machines works - some don't any commonalities with machines who doesn't? has it ever worked on these machines?

SteinarHrafn commented 4 years ago

I will try to find out tomorrow what those machines have in common. We just put the new way of using containers into development yesterday so that method has not worked on those machines before. new-navcontainer has however worked on them and does still work on them, just tested that.

SteinarHrafn commented 4 years ago

I have been unable to find anything linking them. All of them have been able to run containers with: mcr.microsoft.com/businesscentral/onprem:16.2.13509.13779-w1-ltsc2019 mcr.microsoft.com/businesscentral/onprem:16.3.14085.14238-w1-ltsc2019 I did test on one of them yesterday that the 16.2 one still definitely still worked.

Everyone is on the same OS build Its not the computer type Docker is fully up to date on all machines

Any suggestions what I could look for? Could a different generic image help maybe?

freddydk commented 4 years ago

If you run this image: mcr.microsoft.com/businesscentral/onprem:16.2.13509.13779-w1-ltsc2019 and post the full output here. Then run the same image and add -useBestContainerOS and post the full output here. Thanks

SteinarHrafn commented 4 years ago

PS C:\WINDOWS\system32> New-BCContainer -containerName 'test1' -accept_outdated -accept_eula -auth NavUserPassword -memoryLimit 10G -isolation hyperv -imageName "mcr.microsoft.com/businesscentral/onprem:16.2.13509.13779-w1"

NavContainerHelper is version 0.7.0.25 NavContainerHelper is running as administrator Host is Microsoft Windows 10 Enterprise - 1909 Docker Client Version is 19.03.12 Docker Server Version is 19.03.12 Fetching all docker images WARNING: You are running specific Docker images from mcr.microsoft.com. These images will no longer be updated, you should switch to user Docker artifacts. See https://freddysblog.com/2020/07/05/ july-updates-are-out-they-are-the-last-on-premises-docker-images/ Using image mcr.microsoft.com/businesscentral/onprem:16.2.13509.13779-w1-ltsc2019 Creating Container test1 Version: 16.2.13509.13779-W1 Style: onprem Platform: 16.0.13440.13772 Generic Tag: 0.0.9.99 Container OS Version: 10.0.17763.973 (ltsc2019) Host OS Version: 10.0.18363.1016 (1909) Using locale en-US Using hyperv isolation Disabling the standard eventlog dump to container log every 2 seconds (use -dumpEventLog to enable) Files in C:\ProgramData\NavContainerHelper\Extensions\test1\my:

Files: http://test1:8080/ALLanguage.vsix

WARNING: You are running a container which is 187 days old. Microsoft recommends that you always run the latest version of our containers.

Initialization took 108 seconds Ready for connections! Reading CustomSettings.config from test1 Creating Desktop Shortcuts for test1 Container test1 successfully created

SteinarHrafn commented 4 years ago

PS C:\WINDOWS\system32> New-BCContainer -containerName 'test2' -accept_outdated -accept_eula -auth NavUserPassword -memoryLimit 10G -isolation hyperv -imageName "mcr.microsoft.com/businesscentral/onprem:16.2.13509.13779-w1" ` -UseBestContainerOS

NavContainerHelper is version 0.7.0.25 NavContainerHelper is running as administrator Host is Microsoft Windows 10 Enterprise - 1909 Docker Client Version is 19.03.12 Docker Server Version is 19.03.12 Fetching all docker images WARNING: You are running specific Docker images from mcr.microsoft.com. These images will no longer be updated, you should switch to user Docker artifacts. See https://freddysblog.com/2020/07/05/ july-updates-are-out-they-are-the-last-on-premises-docker-images/ Using image mcr.microsoft.com/businesscentral/onprem:16.2.13509.13779-w1-ltsc2019 Creating Container test2 Version: 16.2.13509.13779-W1 Style: onprem Platform: 16.0.13440.13772 Generic Tag: 0.0.9.99 Container OS Version: 10.0.17763.973 (ltsc2019) Host OS Version: 10.0.18363.1016 (1909) A better Generic Container OS exists for your host (mcr.microsoft.com/dynamicsnav:10.0.18363.1016-generic) Creating temp container from mcr.microsoft.com/businesscentral/onprem:16.2.13509.13779-w1-ltsc2019 and extract necessary files Extracting Service Tier and WebClient Files docker : Error response from daemon: hcsshim::PrepareLayer - failed failed in Win32: Incorrect function. (0x1) At C:\Program Files\WindowsPowerShell\Modules\navcontainerhelper\0.7.0.25\ContainerHandling\Extract-FilesFromStoppedNavContainer.ps1:68 char:9

docker : Error response from daemon: hcsshim::PrepareLayer - failed failed in Win32: Incorrect function. (0x1) At C:\Program Files\WindowsPowerShell\Modules\navcontainerhelper\0.7.0.25\ContainerHandling\Extract-FilesFromStoppedNavContainer.ps1:69 char:9

Extracting Windows Client Files docker : Error response from daemon: hcsshim::PrepareLayer - failed failed in Win32: Incorrect function. (0x1) At C:\Program Files\WindowsPowerShell\Modules\navcontainerhelper\0.7.0.25\ContainerHandling\Extract-FilesFromStoppedNavContainer.ps1:72 char:9

Extracting Configuration packages Extracting Test Assemblies Extracting Test Toolkit Extracting Upgrade Toolkit Extracting Extensions Extracting Applications Extracting Applications.W1 Get-Item : Cannot find path 'C:\ProgramData\NavContainerHelper\16.2.13509.13779-W1-Files\ServiceTier\Program Files\Microsoft Dynamics NAV' because it does not exist. At C:\Program Files\WindowsPowerShell\Modules\navcontainerhelper\0.7.0.25\ContainerHandling\Extract-FilesFromStoppedNavContainer.ps1:88 char:26

The property 'FullName' cannot be found on this object. Verify that the property exists. At C:\Program Files\WindowsPowerShell\Modules\navcontainerhelper\0.7.0.25\ContainerHandling\Extract-FilesFromStoppedNavContainer.ps1:88 char:9

You cannot call a method on a null-valued expression. At C:\Program Files\WindowsPowerShell\Modules\navcontainerhelper\0.7.0.25\ContainerHandling\Extract-FilesFromStoppedNavContainer.ps1:89 char:9

New-Item : Cannot bind argument to parameter 'Path' because it is null. At C:\Program Files\WindowsPowerShell\Modules\navcontainerhelper\0.7.0.25\ContainerHandling\Extract-FilesFromStoppedNavContainer.ps1:90 char:24

Move-Item : Cannot bind argument to parameter 'Path' because it is null. At C:\Program Files\WindowsPowerShell\Modules\navcontainerhelper\0.7.0.25\ContainerHandling\Extract-FilesFromStoppedNavContainer.ps1:91 char:25

Get-Item : Cannot find path 'C:\ProgramData\NavContainerHelper\16.2.13509.13779-W1-Files\ServiceTier\Program Files\Microsoft Dynamics NAV' because it does not exist. At C:\Program Files\WindowsPowerShell\Modules\navcontainerhelper\0.7.0.25\ContainerHandling\Extract-FilesFromStoppedNavContainer.ps1:93 char:23

Get-Item : Cannot find path 'C:\ProgramData\NavContainerHelper\16.2.13509.13779-W1-Files\RoleTailoredClient\Program Files\Microsoft Dynamics NAV' because it does not exist. At C:\Program Files\WindowsPowerShell\Modules\navcontainerhelper\0.7.0.25\ContainerHandling\Extract-FilesFromStoppedNavContainer.ps1:101 char:23

Extracting Files from Run folder docker : Error response from daemon: hcsshim::PrepareLayer - failed failed in Win32: Incorrect function. (0x1) At C:\Program Files\WindowsPowerShell\Modules\navcontainerhelper\0.7.0.25\ContainerHandling\Extract-FilesFromStoppedNavContainer.ps1:111 char:9

Extracting Database Files Downloading prerequisites get-childitem : Cannot find path 'C:\ProgramData\NavContainerHelper\16.2.13509.13779-W1-Files\ServiceTier\Program Files\Microsoft Dynamics NAV' because it does not exist. At C:\Program Files\WindowsPowerShell\Modules\navcontainerhelper\0.7.0.25\ContainerHandling\Extract-FilesFromStoppedNavContainer.ps1:120 char:23

The property 'Name' cannot be found on this object. Verify that the property exists. At C:\Program Files\WindowsPowerShell\Modules\navcontainerhelper\0.7.0.25\ContainerHandling\Extract-FilesFromStoppedNavContainer.ps1:120 char:9

Downloading C:\ProgramData\NavContainerHelper\16.2.13509.13779-W1-Files\Prerequisite Components\IIS URL Rewrite Module\rewrite_2.0_rtw_x64.msi Downloading C:\ProgramData\NavContainerHelper\16.2.13509.13779-W1-Files\Prerequisite Components\Open XML SDK 2.5 for Microsoft Office\OpenXMLSDKv25.msi Performing cleanup Get-ChildItem : Cannot find path 'C:\ProgramData\NavContainerHelper\16.2.13509.13779-W1-Files\databases' because it does not exist. At C:\Program Files\WindowsPowerShell\Modules\navcontainerhelper\0.7.0.25\ContainerHandling\Extract-FilesFromStoppedNavContainer.ps1:140 char:23

Get-Item : Cannot find path 'C:\ProgramData\NavContainerHelper\16.2.13509.13779-W1-Files\DATA' because it does not exist. At C:\Program Files\WindowsPowerShell\Modules\navcontainerhelper\0.7.0.25\ContainerHandling\Extract-FilesFromStoppedNavContainer.ps1:149 char:28

Cannot locate database At C:\Program Files\WindowsPowerShell\Modules\navcontainerhelper\0.7.0.25\ContainerHandling\Extract-FilesFromStoppedNavContainer.ps1:156 char:21

freddydk commented 4 years ago

Something is seriously wrong on this machine. Could you try to run the tool from this blog post: https://freddysblog.com/2018/12/11/clean-up-after-yourself-docker-your-mom-isnt-here/ (removes all containers and images)

SteinarHrafn commented 4 years ago

The script from https://freddysblog.com/2018/12/11/clean-up-after-yourself-docker-your-mom-isnt-here/ ran successfully. The Output is below.
Restarted the machine after running the script. Then Docker gave an error.
Selected Reset to Factory defaults and Docker started successfully Repeated the step to run image: mcr.microsoft.com/businesscentral/onprem:16.2.13509.13779-w1-ltsc2019 and it was successful And then the same image with -useBestContainerOS, unsuccessful, output identical to the previous attempt.

OUTPUT: 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\NavContainerHelper. Are you absolutely sure you want to do this? (This cannot be undone) Type Yes to continue:Yes Running Docker System Prune Total reclaimed space: 0B Removing all containers (forced) Stopping Docker Service 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 Cleaning up C:\ProgramData\NavContainerHelper

freddydk commented 4 years ago

Maybe you should try this: https://stackoverflow.com/questions/58986352/docker-build-fails-always-with-error-hcsshimpreparelayer-failed-failed-in-wi

HilmarVil commented 4 years ago

Tried the suggested solutions in that thread but no luck

freddydk commented 4 years ago

Ok, in the end I am afraid that this problem is a docker problem and not related to NAV/BC or NavContainerHelper. I haven't seen this before and the problem is machine specific/docker installation specific. An update to Windows 2004 might solve the issue, but I don't know.

SteinarHrafn commented 4 years ago

Hi Freddy,

While I understand that this is not a navcontainerhelper specific issue the fact remains that we have at least 3 developers now unable to work after the latest changes and an understandable hesitation from a few others to move over until this is resolved in one way or another. It seems related to the flag -useBestContainerOS as you have shown. Is there a way to use the new method without that specific functionality?

freddydk commented 4 years ago

-useBestContainerOS installs the version on-the-fly (like artifacts) - and that (for some reason) fails on your machines.

The only workaround you could do would be to create the image (New-BcImage) on a machine that works and push the image to a private container registry.

Whether it is related to version of Windows (an update to latest Windows 10 might do the trick), antivirus software or other things, I do not know.

I can safely say, that the scripts you are running works on 100's of other machines and I am unable to troubleshoot the individual machines for deep down docker issues.

Sorry