上一节中,我们已经准备好了 SQL Server,那么接下来,我们要把 ASE 放到容器里了。

  首先,新建 Start.ps1,内容如下:

 param(
[Parameter(Mandatory=$true)][string]$HostName,
[string]$AccountName,
[string]$AuthKey,
[string]$SqlServerInstance) # Initialized?
if (Test-Path Initialized)
{
&"C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" start -inporcess
} if ([string]::IsNullOrEmpty($AccountName))
{
Write-Output "AccountName argument not specified, use the default: devstoreaccount1"
$AccountName = "devstoreaccount1"
}
if ([string]::IsNullOrEmpty($AuthKey))
{
Write-Output "AuthKey argument not specified, use the default: Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="
$AuthKey = "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="
}
if ([string]::IsNullOrEmpty($SqlServerInstance))
{
Write-Output "SqlServerInstance argument not specified, use the default: (localdb)\MSSQLLocalDB"
$SqlServerInstance = "(localdb)\MSSQLLocalDB"
} # Replace the configuration
$config = "C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe.config"
(get-content $config)`
-Replace "<service name=""Blob"" url=""http://127.0.0.1:10000/""/>", "<service name=""Blob"" url=""http://$AccountName.blob.$HostName/"" />"`
-Replace "<service name=""Queue"" url=""http://127.0.0.1:10001/""/>", "<service name=""Queue"" url=""http://$AccountName.queue.$HostName/"" />"`
-Replace"<service name=""Table"" url=""http://127.0.0.1:10002/""/>", "<service name=""Table"" url=""http://$AccountName.table.$HostName/"" />"`
-Replace "<account name=""devstoreaccount1"" authKey=""Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="" />",`
"<account name=""$AccountName"" authKey=""$AuthKey"" />"`
| Out-File $config # Init the emulator
& "C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" init -server $SqlServerInstance # Set Initialized flag
New-Item Initialized # Start!
& "C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" start -inprocess

  Dockerfile:

# escape=`

FROM microsoft/windowsservercore

ADD https://go.microsoft.com/fwlink/?linkid=717179&clcid=0x409 MicrosoftAzureStorageEmulator.msi
RUN msiexec /q /i MicrosoftAzureStorageEmulator.msi
RUN del MicrosoftAzureStorageEmulator.msi
COPY Start.ps1 . # Azure Storage Emulator
EXPOSE 80 # Configure and launch
ENTRYPOINT 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(三):运行在容器中的更多相关文章

  1. 在 Windows Server Container 中运行 Azure Storage Emulator(二):使用自定义的 SQL Server Instance

    上一节,我们解决了 Azure Storage Emulator 自定义监听地址的问题,这远远不够,因为在我们 DEV/QA 环境有各自的 SQL Server Instance,我们需要将 ASE ...

  2. 在 Windows Server Container 中运行 Azure Storage Emulator(一):能否监听自定义地址?

    我要做什么? 改 ASE 的监听地址.对于有强迫症的我来说,ASE 默认监听的是 127.0.0.1:10000-10002,这让我无法接受,所以我要将它改成域名 + 80 端口的方式: 放到容器中. ...

  3. 如何在ASP.NET Core中自定义Azure Storage File Provider

    文章标题:如何在ASP.NET Core中自定义Azure Storage File Provider 作者:Lamond Lu 地址:https://www.cnblogs.com/lwqlun/p ...

  4. Azure开发者任务之一:解决Azure Storage Emulator初始化失败

    初学Windows Azure: 我打算开始学习Windows Azure.我安装了Azure SDK,然后在“Cloud”标签下选择Windows Azure模板,创建了一个项目,然后又创建了一个W ...

  5. 说一说windows原生docker及windows Server Container , Hyper Container 之间的关系(学习总结)

    前一段时间学习netcore的时候解除到了docker,感觉真是不错的技术.百度了不少教程.因为我用windows就下载安装了一下试试.但是没有安装成功,才发现 需要安装virtualbox虚拟机,与 ...

  6. Windows Server 2016软件定义存储:Storage Spaces Direct的关键特性

    [TechTarget中国原创] 微软在Windows Server 2016 Technical Preview 2中引入了Storage Spaces Direct.这个特性将本地存储扩展为高可用 ...

  7. Windows Server 2016-客户端退域的三种方法

    前边我们提到了客户端加域的操作方法,本章为大家补充域客户端退域的操作过程,包含图形化.netdom remove.Powershell三种方法,具体内容如下: 图形化退域方法: 1.Win键,计算机右 ...

  8. [转]探索 Windows Azure Storage

    本文转自:https://msdn.microsoft.com/zh-tw/jj573842 概觀 儲存服務 (Storage services) 在 Windows Azure 運算模擬器中提供了可 ...

  9. Visual Studio 2017 调试 windows server 2016 Docker Container

    网上很多文章都是在win10下,用Docker for windows工具进行Docker的安装部署的.用知道windows server 2016已经原生支持Docker了,其windows Con ...

随机推荐

  1. 二叉查找树 Java实现

    定义: 一棵二叉查找树是一棵二叉树,每个节点都含有一个Comparable的键(以及对应的值). 每个节点的键都大于左子树中任意节点的键而小于右子树中任意节点的键. 树的术语: Name Functi ...

  2. jar命令简单使用

    以windows10操作系统,JDK1.8为例: 打包主要是针对class文件以及依赖的jar包. 1.编写MANIFEST.MF文件(详细可以上网查一下MANIFEST.MF文件规则.) 此文件主要 ...

  3. 【原】公司P2P平台的功能拆分

    银行回调:由原来写在PC门户项目中拆分开来,作为一个专门处理回调的项目,配置多个数据源,实时写入数据库. 定时回查:由原来写在PC后台管理项目中拆分开来,作为一个专门回查银行网关的项目. 请求银行:由 ...

  4. SpringBoot(四) Core Features: Logging

    参考 文档: 26. Logging

  5. 高并发第十单:J.U.C AQS(AbstractQueuedSynchronizer) 组件:CountDownLatch. CyclicBarrier .Semaphore

    这里有一篇介绍AQS的文章 非常好: Java并发之AQS详解 AQS全名:AbstractQueuedSynchronizer,是并发容器J.U.C(java.lang.concurrent)下lo ...

  6. Android - Builder模式

    https://github.com/simple-android-framework-exchange/android_design_patterns_analysis/tree/master/bu ...

  7. php 多次导入文件导致 Cannot redeclare class

    定义了类A b.php中导入了A c.php中导入了b.php c.php中导入A会报错:

  8. 理解 RESTful 架构(转)

    前言:REST指的是一组架构约束条件和原则." 如果一个架构符合REST的约束条件和原则,我们就称它为RESTful架构. 越来越多的人开始意识到,网站即软件,而且是一种新型的软件. 这种& ...

  9. centos7下安装sublime text3并配置环境变量

    注意:我解压完把sublime_text全改成了sublime,如果未改就是sublime_text 1.官网下载sublime,保存到指定目录,例如/home 2.解压 tar xjf sublim ...

  10. HTML标签参考(二)

    一些重要的标签 • ol li  <ol><li></li></ol>这是一组标签,它们二者都是成对出现的,每一个标签单独出现都是没有意义的事情. 这一 ...