If you haven’t read the first post about the NavContainerHelper, you should do so.
The following script sample, will create a new SQL Server container and restore a NAV 2018 database backup file (Demo Database NAV (11-0).bak) placed on the host in a folder called c:\temp\navdbfiles. The folder c:\temp\navdbfiles on the host is shared as c:\temp inside the container.
$hostFolder = "c:\temp\navdbfiles"
$databaseCredential = New-Object System.Management.Automation.PSCredential -argumentList "sa", (ConvertTo-SecureString -String "P@ssword1" -AsPlainText -Force)
$dbPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($databaseCredential.Password))
$dbserverid = docker run -d -e sa_password="$dbPassword" -e ACCEPT_EULA=Y -v "${hostFolder}:C:/temp"
$databaseServer = $dbserverid.SubString(0,12)
$databaseInstance = ""
$databaseName = "Demo Database NAV (11-0)"
$databaseServerInstance = @{ $true = "$databaseServer$databaseInstance"; $false = "$databaseServer"}["$databaseInstance" -ne ""]
$RelocateData = New-Object Microsoft.SqlServer.Management.Smo.RelocateFile("${databaseName}_Data", "c:\temp\${databaseName}_Data.mdf")
$RelocateLog = New-Object Microsoft.SqlServer.Management.Smo.RelocateFile("${databaseName}_Log", "c:\temp\${databaseName}_Log.ldf")
Restore-SqlDatabase -ServerInstance $databaseServerInstance -Database $databaseName -BackupFile "C:\temp\$databaseName.bak" -Credential $databaseCredential -RelocateFile @($RelocateData,$RelocateLog)
After this, the SQL Server is ready to use from a NAV container and the variables $databaseServer, $databaseInstance, $databaseName and $databaseCredential are the parameters used to start up a NAV container to use this new database server.
Enjoy
Freddy Kristiansen
Technical Evangelist
Hello,
Is it possible to share another drive instead of c:\ ?
I yes how can i manage it on windows docker container ?
LikeLike
ContainerHelper is hardcoded to run on C:
Docker can change to other drives – I haven’t tried this myself.
in ContainerHelper – you can run Flush-ContainerHelperCache to remove all redundant cache information. Some things will then be slower next time around, but unused stuff will not be back.
LikeLike
Ok I tried. I set up data-root on a network drive.
I run the new-navcontainer cmdlet and I got his error message ;
DockerDo : failed to register layer: re-exec error: exit status 1: output: BackupWrite \\?\Z:\docker\windowsfilter\fd21893974d7389f66f94eabb458c0f140e8afdee07832173ca75d5873117c71\Files: The specified account
does not exist.
ExitCode: 1
Commandline: docker pull microsoft/dynamics-nav:2018-cu6-fr
Au caractère C:\Program Files\WindowsPowerShell\Modules\navcontainerhelper\0.6.5.0\ContainerHandling\New-NavContainer.ps1:442 : 13
+ DockerDo -command pull -imageName $imageName | Out-Null
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,DockerDo
Did you see what is exactly this error ?Credentials problem ?
LikeLike
It looks like docker doesn’t support network drives or you have specified the drive wrongly.
LikeLike
Hello,
I tried to run the script and I have the following error :
docker : “docker run” requires at least 1 argument.
Au caractère Ligne:5 : 15
+ … bserverid = docker run -d -e sa_password=”$dbPassword” -e ACCEPT_EULA …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (“docker run” re…ast 1 argument.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
See ‘docker run –help’.
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG…]
Run a command in a new container
Impossible d’appeler une méthode dans une expression Null.
Au caractère Ligne:6 : 1
+ $databaseServer = $dbserverid.SubString(0,12)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation : (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
I think it is related to the docker run with parameters -d. It should be filled : what i supposed to enter for this command ?
LikeLike
Not sure SQL containers are supported anymore – there are much newer blog posts on how to do things – also creating containers which uses SQL installed on the host.
LikeLike