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

Failed to create container with spaces in path to the shared folder #3136

Closed kpipic closed 1 year ago

kpipic commented 1 year ago

PLEASE DO NOT INCLUDE ANY PASSWORDS OR TOKENS IN YOUR ISSUE!!!

Describe the issue Creating of container failed with: $Params += @{ additionalParameters = $AdditionalParameters } when $AdditionalParameters += '--volume {0}:{1}' -f $RepositoryDirectory, $RepositoryDirectory

$RepositoryDirectory contains spaces in path

Scripts used to create container and cause the issue

$ContainerName = 'sandbox1'
$Credential = Get-Credential

$RepositoryDirectory = Get-Location
Write-Host $RepositoryDirectory
$AdditionalParameters = @()
$AdditionalParameters += '--volume {0}:{1}' -f $RepositoryDirectory, $RepositoryDirectory
$artifactUrl = Get-BCArtifactUrl -country w1 -select Latest -storageAccount bcartifacts -type Sandbox

$Params = @{}
$Params += @{ accept_eula = $true }
$Params += @{ artifactUrl = $artifactUrl }
$Params += @{ containerName = $ContainerName }
#$Params += @{ licenseFile = $LicenseFile }
$Params += @{ auth = 'NavUserPassword' }
$Params += @{ credential = $Credential }
#$Params += @{ isolation = 'process' }
#$Params += @{ isolation = 'hyperv' }
#$Params += @{ memoryLimit = '4G' }
#$Params += @{ updateHosts = $true }
$Params += @{ accept_outdated  = $true }
$Params += @{ useBestContainerOS = $true }
$Params += @{ additionalParameters = $AdditionalParameters }

New-BcContainer @Params

Full output of scripts

PS C:\temp with space> $ContainerName = 'sandbox1'
$Credential = Get-Credential

$RepositoryDirectory = Get-Location
Write-Host $RepositoryDirectory
$AdditionalParameters = @()
$AdditionalParameters += '--volume {0}:{1}' -f $RepositoryDirectory, $RepositoryDirectory
$artifactUrl = Get-BCArtifactUrl -country w1 -select Latest -storageAccount bcartifacts -type Sandbox

$Params = @{}
$Params += @{ accept_eula = $true }
$Params += @{ artifactUrl = $artifactUrl }
$Params += @{ containerName = $ContainerName }
#$Params += @{ licenseFile = $LicenseFile }
$Params += @{ auth = 'NavUserPassword' }
$Params += @{ credential = $Credential }
#$Params += @{ isolation = 'process' }
#$Params += @{ isolation = 'hyperv' }
#$Params += @{ memoryLimit = '4G' }
#$Params += @{ updateHosts = $true }
$Params += @{ accept_outdated  = $true }
$Params += @{ useBestContainerOS = $true }
$Params += @{ additionalParameters = $AdditionalParameters }

New-BcContainer @Params
cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
C:\temp with space
BcContainerHelper version 5.0.3
Setting TraefikUseDnsNameAsHostName = False
Setting SendExtendedTelemetryToMicrosoft = False
Setting baseUrl = https://businesscentral.dynamics.com
Setting PartnerTelemetryConnectionString = 
Setting useSharedEncryptionKeys = True
Setting psSessionTimeout = 0
Setting addTryCatchToScriptBlock = True
Setting MinimumDotNetRuntimeVersion = @{Major=6; Minor=0; Build=16; Revision=-1; MajorRevision=-1; MinorRevision=-1}
Setting digestAlgorithm = SHA256
Setting defaultNewContainerParameters = @{Credential=; Accept_Eula=True; Isolation=Process; UpdateHosts=True; Auth=UserPassword}
Setting mapNetworkSettings = 
Setting ObjectIdForInternalUse = 88123
Setting useVolumes = False
Setting DebugMode = False
Setting killPsSessionProcess = False
Setting WarningPreference = SilentlyContinue
Setting sandboxContainersAreMultitenantByDefault = True
Setting NoOfSecondsToSleepAfterPublishBcContainerApp = 1
Setting containerHelperFolder = C:\ProgramData\BcContainerHelper
Setting AddHostDnsServersToNatContainers = False
Setting useCompilerFolder = False
Setting TreatWarningsAsErrors = 
Setting apiBaseUrl = https://api.businesscentral.dynamics.com
Setting bcartifactsCacheFolder = c:\bcartifacts.cache
Setting TraefikImage = tobiasfenster/traefik-for-windows:v1.7.34
Setting use7zipIfAvailable = True
Setting DOCKER_SCAN_SUGGEST = False
Setting genericImageName = mcr.microsoft.com/businesscentral:{0}
Setting mapCountryCode = @{ae=w1; ar=w1; bd=w1; dz=w1; cl=w1; pr=w1; eg=w1; fo=dk; gl=dk; id=w1; ke=w1; lb=w1; lk=w1; lu=w1; ma=w1; mm=w1; mt=w1; my=w1; ng=w1; qa=w1; sa=w1; sg=w1; 
tn=w1; ua=w1; za=w1; ao=w1; bh=w1; ba=w1; bw=w1; cr=br; cy=w1; do=br; ec=br; sv=br; gt=br; hn=br; jm=w1; mv=w1; mu=w1; ni=br; pa=br; py=br; tt=br; uy=br; zw=w1}
Setting UseNewFormatForGetBcContainerAppInfo = False
Setting usePsSession = True
Setting timeStampServer = http://timestamp.digicert.com
Setting genericImageNameFilesOnly = mcr.microsoft.com/businesscentral:{0}-filesonly
Setting MicrosoftTelemetryConnectionString = InstrumentationKey=5b44407e-9750-4a07-abe9-30c3b853821b;IngestionEndpoint=https://southcentralus-0.in.applicationinsights.azure.com/
Setting WinRmCredentials = 
Setting hostHelperFolder = C:\ProgramData\BcContainerHelper
Setting useVolumeForMyFolder = False
Setting defaultContainerName = bcserver
Setting MinimumDotNetRuntimeVersionUrl = https://download.visualstudio.microsoft.com/download/pr/ca13c6f1-3107-4cf8-991c-f70edc1c1139/a9f90579d827514af05c3463bed63c22/dotnet-sdk-6.0
.408-win-x64.zip
Setting RenewClientContextBetweenTests = False
BC.HelperFunctions emits usage statistics telemetry to Microsoft
Default parameter Isolation = Process
Default parameter UpdateHosts = True
BcContainerHelper is version 5.0.3
BcContainerHelper is running as administrator
HyperV is Enabled
UsePsSession is True
Host is Microsoft Windows 11 Pro - 10.0.22621.1992
Docker Client Version is 24.0.2
Docker Server Version is 24.0.2
Removing Desktop shortcuts
Waiting for other process downloading artifact 'https://bcartifacts.azureedge.net/sandbox/22.3.58346.59090/w1'
Other process completed download
Fetching all docker images
Fetching all docker volumes
Using image mcr.microsoft.com/businesscentral:10.0.20348.1850
Creating Container sandbox1
Style: sandbox
Multitenant: Yes
Version: 22.3.58346.59090
Platform: 22.0.59032.0
Generic Tag: 1.0.2.14
Container OS Version: 10.0.20348.1850 (ltsc2022)
Host OS Version: 10.0.22621.1992 (22H2)
Using Process isolation
Using locale en-US
Disabling the standard eventlog dump to container log every 2 seconds (use -dumpEventLog to enable)
Additional Parameters:
--volume C:\temp with space:C:\temp with space
Files in C:\ProgramData\BcContainerHelper\Extensions\sandbox1\my:
- AdditionalOutput.ps1
- MainLoop.ps1
- SetupVariables.ps1
- updatehosts.ps1
Creating container sandbox1 from image mcr.microsoft.com/businesscentral:10.0.20348.1850
New-BcContainer Telemetry Correlation Id: 91c58c7d-1840-4327-8a6f-b145be36a301
DockerDo : Unable to find image 'with:latest' locally
docker: Error response from daemon: pull access denied for with, repository does not exist or may require 'docker login': denied: requested access to the resource is denied.
See 'docker run --help'.
ExitCode: 125
Commandline: docker run --volume "c:\bcartifacts.cache:c:\dl" --label nav= --env isBcSandbox=Y --label version=22.3.58346.59090 --label platform=22.0.59032.0 --label country=W1 --e
nv artifactUrl=https://bcartifacts.azureedge.net/sandbox/22.3.58346.59090/w1 --env multitenant=Y --env licenseFile="" --name sandbox1 --hostname sandbox1 --env auth=NavUserPassword
 --env username="kpipic" --env ExitOnError=N --env locale=en-US --env databaseServer="" --env databaseInstance="" --volume "C:\ProgramData\BcContainerHelper:C:\ProgramData\BcContai
nerHelper" --volume "C:\ProgramData\BcContainerHelper\Extensions\sandbox1\my:C:\Run\my" --isolation Process --restart unless-stopped --env filesOnly=False --env enableApiServices=Y
 --env useSSL=N --volume "c:\windows\system32\drivers\etc:C:\driversetc" --env securePassword=76492d1116743f0423413b16050a5345MgB8AFEATwBNAGsAaQBLADIAYQBwAFQAVwBPADQAUwA0ADMAegBiAE
IATQBNAFEAPQA9AHwAMgA1ADAAMgAzAGMAMgA4ADQAMABlAGQAOQA3AGYANQAzADcAZABlAGYANABmADcAZAA4AGEAMQBkADcANgAyADUAZQA0ADcANgA5AGQAMgBmAGMAOAAyADEAMABjADMANwAwAGEANQA4ADUAZgA1ADkAOAA5ADEAMg
A3ADIAZQA= --env passwordKeyFile="c:\run\my\aes.key" --env removePasswordKeyFile=Y --volume C:\temp with space:C:\temp with space --env accept_eula=Y --env accept_outdated=Y --deta
ch mcr.microsoft.com/businesscentral:10.0.20348.1850
At C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\5.0.3\ContainerHandling\New-NavContainer.ps1:1949 char:15
+ ...       if (!(DockerDo -accept_eula -accept_outdated:$accept_outdated - ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,DockerDo
...

Screenshots image

Additional context Container created with the same script but $RepositoryDirectory does not contains spaces in path: image

freddydk commented 1 year ago

Change this:

$AdditionalParameters += '--volume {0}:{1}' -f $RepositoryDirectory, $RepositoryDirectory to

$AdditionalParameters += '--volume "{0}:{1}"' -f $RepositoryDirectory, $RepositoryDirectory

that should fix the issue