Dockerfile CMD - There can only be one.



Regardless of current or previously configure docker image, CMD can only be executed once.

For example, let's say you use image PARENT_IMAGE_DOCKER and it uses a CMD to build this image. If you build on top of PARENT_IMAGE_DOCKER  and call it CHILD_IMAGE_DOCKER, you are still stuck with running / configuring a single CMD.

Image builder needs to be careful. The work around for this is to use a script (mountdb.script) which gets called and the runs whatever scripts that PARENT_IMAGE_DOCKER requires.

You can see some samples here (Notice on line 36, I called .\start.ps1 - which is what the image used to run.

# Example environment configuratiopn
# $targetRestorePath = "C:\MSSQLDATA\DATA\"
# $env:restore_dbs = "[{'dbName':'ProductCatalog','DBLogicalName':'Bunnings.CommerceServer.ProductCatalog', 'Bakfilename':'C:\\mssqldata\\ProductCatalog.bak'}]"
$targetRestorePath = $env:targetRestorePath
$env:restore_dbs = "[{'dbName':'ProductCatalog','DBLogicalName':'Bunnings.CommerceServer.ProductCatalog', 'Bakfilename':'C:\\mssqldata\\ProductCatalog.bak'}]"
$restore_dbs = $env:restore_dbs
Write-Host "Database(s) to restore $restore_dbs to $targetRestorePath"
$dbs = $restore_dbs | ConvertFrom-Json
# Check if we have some environment configuration settings
if ($null -ne $dbs -And $dbs.Length -gt 0)
{
Write-Verbose "Restoring database $($dbs.Length) database(s)"
Foreach($db in $dbs)
{
$targetDbName = $db.dbName
$targetDbBakFile = $db.Bakfilename
$targetLogialDb = $db.DBLogicalName
$targetLogialDbLog = $db.DBLogicalName + "_log"
$sqlcmd = "RESTORE DATABASE [$targetDbName] FROM DISK = '$targetDbBakFile' WITH REPLACE, MOVE N'$targetLogialDb' TO N'$targetRestorePath$targetLogialDb" + ".mdf'," + " MOVE N'$targetLogialDbLog' TO N'$targetRestorePath$targetLogialDbLog" + ".ldf'"
Write-Host $sqlcmd
Write-Verbose "Invoke-Sqlcmd -Query $($sqlcmd)"
Invoke-Sqlcmd -Query $sqlcmd -ServerInstance "localhost"
}
}
Write-Host "Running image start scripts."
.\start -sa_password $env:sa_password -ACCEPT_EULA $env:ACCEPT_EULA -attach_dbs \"$env:attach_dbs\" -Verbose
view raw mountdb.ps1 hosted with ❤ by GitHub


Comments

Popular posts from this blog

The specified initialization vector (IV) does not match the block size for this algorithm

NodeJS: Error: spawn EINVAL in window for node version 20.20 and 18.20