microsoft / navcontainerhelper

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

Cannot create the container with ISV from Docker Hub repo #807

Closed Pavel-Titov closed 4 years ago

Pavel-Titov commented 4 years ago

Hi all, I am facing the following problems when creating the container from my own repo:

$navcredential = New-Object System.Management.Automation.PSCredential -argumentList "admin", (ConvertTo-SecureString -String "P@ssword1" -AsPlainText -Force)
New-NavContainer -accept_eula -accept_outdated -containerName bc15knk-test2 -credential $credentials -Auth NavUserPassword -imageName knk1/bc15knk:latest -useBestContainerOS -includeAL -updateHosts -doNotExportObjectsToText

NavContainerHelper is version 0.6.4.20
NavContainerHelper is running as administrator
Host is Microsoft  - 1903
Docker Client Version is 19.03.4
Docker Server Version is 19.03.4
Using image knk1/bc15knk:latest
Creating Container bc15knk-test2
Version: 15.0.36560.0-W1
Style: onprem
Platform: 15.0.36510.0
Generic Tag: 0.0.9.96
Container OS Version: 10.0.18362.418 (1903)
Host OS Version: 10.0.18362.535 (1903)
WARNING: The container operating system matches the host operating system, but the revision is different.
If you encounter issues, you might want to specify -isolation hyperv
Using locale en-US
Using process isolation
Disabling the standard eventlog dump to container log every 2 seconds (use -dumpEventLog to enable)
Files in C:\ProgramData\NavContainerHelper\Extensions\bc15knk-test2\my:
- AdditionalOutput.ps1
- MainLoop.ps1
- SetupVariables.ps1
- SetupWebClient.ps1
- updatehosts.ps1
Creating container bc15knk-test2 from image knk1/bc15knk:latest
14051e6b5fddecebaa9826629980a7f67e25ff3aee39a6e4f67dcb3f19e3bea0
Waiting for container bc15knk-test2 to be ready
Initializing...
Setting host.docker.internal to 10.100.30.55 in container hosts file (copy from host hosts file)
Setting gateway.docker.internal to 10.100.30.55 in container hosts file (copy from host hosts file)
Setting host.docker.internal to 192.168.1.10 in container hosts file (copy from host hosts file)
Setting gateway.docker.internal to 192.168.1.10 in container hosts file (copy from host hosts file)
Setting kubernetes.docker.internal to 127.0.0.1 in container hosts file (copy from host hosts file)
Setting host.containerhelper.internal to 172.27.112.1 in container hosts file
Restarting Container
Hostname is 
PublicDnsName is bc15knk-test2
Using NavUserPassword Authentication
Starting Local SQL Server
Starting Internet Information Server
Creating Self Signed Certificate
Self Signed Certificate Thumbprint 88F8FE815BC614C8AAAE4322AFA59C80C5557B1F
Modifying Service Tier Config File with Instance Specific Settings
Starting Service Tier
Service 'Dynamics 365 Business Central Server [BC] (MicrosoftDynamicsNavServer$BC)' cannot be started due to the following error: Cannot start s
ervice MicrosoftDynamicsNavServer$BC on computer '.'.
at <ScriptBlock>, C:\Run\navstart.ps1: line 142
at <ScriptBlock>, C:\Run\start.ps1: line 121
at <ScriptBlock>, <No file>: line 1Error
Initializing...
Setting host.docker.internal to 10.100.30.55 in container hosts file (copy from host hosts file)
Setting gateway.docker.internal to 10.100.30.55 in container hosts file (copy from host hosts file)
Setting host.docker.internal to 192.168.1.10 in container hosts file (copy from host hosts file)
Setting gateway.docker.internal to 192.168.1.10 in container hosts file (copy from host hosts file)
Setting kubernetes.docker.internal to 127.0.0.1 in container hosts file (copy from host hosts file)
Setting host.containerhelper.internal to 172.27.112.1 in container hosts file
Restarting Container
Hostname is 
PublicDnsName is bc15knk-test2
Using NavUserPassword Authentication
Starting Local SQL Server
Starting Internet Information Server
Creating Self Signed Certificate
Self Signed Certificate Thumbprint 88F8FE815BC614C8AAAE4322AFA59C80C5557B1F
Modifying Service Tier Config File with Instance Specific Settings
Starting Service Tier
Service 'Dynamics 365 Business Central Server [BC] (MicrosoftDynamicsNavServer$BC)' cannot be started due to the following error: Cannot start s
ervice MicrosoftDynamicsNavServer$BC on computer '.'.
at <ScriptBlock>, C:\Run\navstart.ps1: line 142
at <ScriptBlock>, C:\Run\start.ps1: line 121
at <ScriptBlock>, <No file>: line 1
Initialization of container bc15knk-test2 failed
In C:\Program Files\WindowsPowerShell\Modules\navcontainerhelper\0.6.4.20\ContainerHandling\Wait-NavContainerReady.ps1:44 Zeichen:17
+ ...             throw "Initialization of container $containerName failed" ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Initialization ...nk-test2 failed:String) [], RuntimeException
    + FullyQualifiedErrorId : Initialization of container bc15knk-test2 failed

also when I am trying to create a container from docker command:

docker run -m 4Gb "knk1/bc15knk:latest"
Initializing...
Restarting Container
Hostname is 947e4b12ae7a
PublicDnsName is 947e4b12ae7a
Using NavUserPassword Authentication
Starting Local SQL Server
Starting Internet Information Server
Creating Self Signed Certificate
Self Signed Certificate Thumbprint F20B930249C46E9ACFBC040AF38F1452B06219E5
Modifying Service Tier Config File with Instance Specific Settings
Starting Service Tier
Registering event sources
Creating DotNetCore Web Server Instance
Access to the path 'Microsoft.AI.Agent.Intercept.dll' is denied.
at New-NavWebSite, C:\Program Files\Microsoft Dynamics NAV\150\Web Client\Modules\NAVWebClientManagement\NAVWebClientManagement.psm1: line 562
at New-NAVWebServerInstance, C:\Program Files\Microsoft Dynamics NAV\150\Web Client\Modules\NAVWebClientManagement\NAVWebClientManagement.psm1: 
line 501
at <ScriptBlock>, C:\Run\SetupWebClient.ps1: line 26
at <ScriptBlock>, C:\Run\navstart.ps1: line 152
at <ScriptBlock>, C:\Run\start.ps1: line 121
at <ScriptBlock>, <No file>: line 1
Starting EventLog Monitor
Monitoring EventSources from EventLog[Application]:
- Microsoft.Dynamics.Nav.Management.dll
- MicrosoftDynamicsNAVClientClientService
- MicrosoftDynamicsNAVClientWebClient
- MicrosoftDynamicsNavServer$BC
- MSSQL$SQLEXPRESS

I built the image by the following command set:

Stop-NavContainer -containerName bc15knk
docker commit bc15knk knk1/bc15knk
docker push knk1/bc15knk
epernst commented 4 years ago

So you started by using New-NavContainer to create your bc15knk container? Then you save (commit) the fully functional bc15knk container and push it to docker hub?

Not tried it my self, but I would think that you don't need to use New-NavContainer to start it again. Instead you should be able to use docker run directly. It may work if you test it using the same machine you created it on, but I doubt that it would work if you use a different docker host. The reason for that is that a NavContainer have a lot of additional setup, which NavContainerHelper creates for each host. But why is it that you cannot use the standard images? If it's because you need it pre-configured with demo-data etc. then just use the standard images plus a backup. Freddy has described how to do this in his blog around November 2019.

Pavel-Titov commented 4 years ago

Hi @epernst Yes, the main reason that the database contains the demodata. Sure, I can make a backup from container and use it to create a new one... Also my container already contains all necessary dlls for dotnet controls for proper function. I want just establish the simple and easy way for DEV and QA to create their environment with one powershell command. I think somewhere in October 2019 I tested the same way and it worked fine. Could it be because of some modifications in the NavContainerHelper?

epernst commented 4 years ago

We have the same issue, our developers need to get the latest and greatest version of our solution (sometimes multiple times per day). So we let our Azure DevOps build pipeline handle it. As part of our build, we create a new database, incl. demo data and published dependency applications. Together with DotNet controls we package this as a Nuget package. This way our developer can download the package and run our script (new-navcontainer, restore db and share dotnet with container). It was actually the post in December I thought about: https://freddysblog.com/2019/12/09/having-demo-data-while-developing-business-central-apps-with-docker/

Pavel-Titov commented 4 years ago

Thanks,, @epernst! Yes, sure, developer can run almost the same script I used to create the container from SQL backup, but I was just thinking why the restoring from the docker hub does not work for me... although I believe it should... as I understood the collision in case of new-navcontainer happens, because the existing file cannot be deleted by the following command in NAVWebClientManagement.psm1 (line 562):

if (Test-Path $siteRootFolder) {
        Write-Verbose "Remove $siteRootFolder"
        **Remove-Item $siteRootFolder -Recurse -Force**
    }

although when I run the same command directly from the container (once the preparation is failed) the file is deleted, so I assume that happens that the Webserver is already running and locking the file...

freddydk commented 4 years ago

It is possible to commit and recreate containers, but it isn't really a supported scenario for NAV/BC containers. You can do a lot of stuff this makes this hard or not possible.

The specific error above might go away if you switch to hyperv isolation, but I still wouldn't recommend the path you are heading down.

A few other issues related to this: https://github.com/microsoft/navcontainerhelper/issues/525 https://github.com/microsoft/navcontainerhelper/issues/754

If you want to create your own images, you can see how this is done using docker build here: https://github.com/microsoft/nav-docker/tree/master/bc-local (this shows how to build a local version of BC based on a W1 image) You could create a DOCKERFILE and create your image based on a local or W1 image.

The simplest and fastest way is to use database backups, there are a lot of options for doing that. You can also place the database on the host and have it running at all times (and/or restore using PS)

Pavel-Titov commented 4 years ago

Ok, we will follow your recommendations and will create a container from SQL backup instead of the DockerHub repository. Thanks!