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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
Comments