標籤:account power name san -- == empty figure ima
上一節中,我們已經準備好了 SQL Server,那麼接下來,我們要把 ASE 放到容器裡了。
首先,建立 Start.ps1,內容如下:
1 param( 2 [Parameter(Mandatory=$true)][string]$HostName, 3 [string]$AccountName, 4 [string]$AuthKey, 5 [string]$SqlServerInstance) 6 7 # Initialized? 8 if (Test-Path Initialized) 9 {10 &"C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" start -inporcess11 }12 13 if ([string]::IsNullOrEmpty($AccountName))14 {15 Write-Output "AccountName argument not specified, use the default: devstoreaccount1"16 $AccountName = "devstoreaccount1"17 }18 if ([string]::IsNullOrEmpty($AuthKey))19 {20 Write-Output "AuthKey argument not specified, use the default: Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="21 $AuthKey = "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="22 }23 if ([string]::IsNullOrEmpty($SqlServerInstance))24 {25 Write-Output "SqlServerInstance argument not specified, use the default: (localdb)\MSSQLLocalDB"26 $SqlServerInstance = "(localdb)\MSSQLLocalDB"27 }28 29 # Replace the configuration30 $config = "C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe.config"31 (get-content $config)`32 -Replace "<service name=""Blob"" url=""http://127.0.0.1:10000/""/>", "<service name=""Blob"" url=""http://$AccountName.blob.$HostName/"" />"`33 -Replace "<service name=""Queue"" url=""http://127.0.0.1:10001/""/>", "<service name=""Queue"" url=""http://$AccountName.queue.$HostName/"" />"`34 -Replace"<service name=""Table"" url=""http://127.0.0.1:10002/""/>", "<service name=""Table"" url=""http://$AccountName.table.$HostName/"" />"`35 -Replace "<account name=""devstoreaccount1"" authKey=""Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="" />",`36 "<account name=""$AccountName"" authKey=""$AuthKey"" />"`37 | Out-File $config38 39 # Init the emulator40 & "C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" init -server $SqlServerInstance41 42 # Set Initialized flag43 New-Item Initialized44 45 # Start!46 & "C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" start -inprocess
Dockerfile:
# escape=`FROM microsoft/windowsservercoreADD https://go.microsoft.com/fwlink/?linkid=717179&clcid=0x409 MicrosoftAzureStorageEmulator.msiRUN msiexec /q /i MicrosoftAzureStorageEmulator.msiRUN del MicrosoftAzureStorageEmulator.msiCOPY Start.ps1 .# Azure Storage EmulatorEXPOSE 80# Configure and launchENTRYPOINT powershell .\Start.ps1
或許把 AzureStorageEmulator.exe" init 放到 Dockerfile 裡也是個好主意,但是這樣每個環境都要 build 不同的 image,這不是我想要的。
現在可以 Build 我們的 image 了:
docker build -t charmsan/azurestorageemulator .
為了使用 gMSA 運行容器,還有一步(有關容器中使用 gMSA,請見我的另一篇博文:《在 Windows 容器中使用 gMSA》):
New-CredentialSpec -Name AseSvc -AccountName AseSvc
Launch!
docker run -it -h ASE-DEV --name AzureStorageEmulator-Dev --network external --ip 192.168.11.1 --dns 192.168.15.1 --dns 192.168.15.2 --security-opt "credentialspec=file://AseSvc.json" --restart unless-stopped charmsan/azurestorageemulator -HostName contoso.com -AccountName dev -SqlServerInstance CONTOSO-ENV-DB\CONTOSO_DEV
運行結果:
請無視掉裡面的兩個錯誤,配置 Azure Storage Explorer 串連:
運行結果:
現在,我們可以修改 Web.Debug.config 來把串連串 transform 一下了:
<add xdt:Transform="SetAttributes" xdt:Locator="Match(key)" key="StorageAccountConnectionString" value="DefaultEndpointsProtocol=http;AccountName=dev;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://dev.blob.contoso.com/dev;" />
不要問我串連串中的 URL 為什麼長成這樣子,因為你肯定沒認真看第一節:)
在 Windows Server Container 中運行 Azure Storage Emulator(三):運行在容器中