在 Windows Server Container 中运行 Azure Storage Emulator(三):运行在容器中
上一节中,我们已经准备好了 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(三):运行在容器中的更多相关文章
- 在 Windows Server Container 中运行 Azure Storage Emulator(二):使用自定义的 SQL Server Instance
上一节,我们解决了 Azure Storage Emulator 自定义监听地址的问题,这远远不够,因为在我们 DEV/QA 环境有各自的 SQL Server Instance,我们需要将 ASE ...
- 在 Windows Server Container 中运行 Azure Storage Emulator(一):能否监听自定义地址?
我要做什么? 改 ASE 的监听地址.对于有强迫症的我来说,ASE 默认监听的是 127.0.0.1:10000-10002,这让我无法接受,所以我要将它改成域名 + 80 端口的方式: 放到容器中. ...
- 如何在ASP.NET Core中自定义Azure Storage File Provider
文章标题:如何在ASP.NET Core中自定义Azure Storage File Provider 作者:Lamond Lu 地址:https://www.cnblogs.com/lwqlun/p ...
- Azure开发者任务之一:解决Azure Storage Emulator初始化失败
初学Windows Azure: 我打算开始学习Windows Azure.我安装了Azure SDK,然后在“Cloud”标签下选择Windows Azure模板,创建了一个项目,然后又创建了一个W ...
- 说一说windows原生docker及windows Server Container , Hyper Container 之间的关系(学习总结)
前一段时间学习netcore的时候解除到了docker,感觉真是不错的技术.百度了不少教程.因为我用windows就下载安装了一下试试.但是没有安装成功,才发现 需要安装virtualbox虚拟机,与 ...
- Windows Server 2016软件定义存储:Storage Spaces Direct的关键特性
[TechTarget中国原创] 微软在Windows Server 2016 Technical Preview 2中引入了Storage Spaces Direct.这个特性将本地存储扩展为高可用 ...
- Windows Server 2016-客户端退域的三种方法
前边我们提到了客户端加域的操作方法,本章为大家补充域客户端退域的操作过程,包含图形化.netdom remove.Powershell三种方法,具体内容如下: 图形化退域方法: 1.Win键,计算机右 ...
- [转]探索 Windows Azure Storage
本文转自:https://msdn.microsoft.com/zh-tw/jj573842 概觀 儲存服務 (Storage services) 在 Windows Azure 運算模擬器中提供了可 ...
- Visual Studio 2017 调试 windows server 2016 Docker Container
网上很多文章都是在win10下,用Docker for windows工具进行Docker的安装部署的.用知道windows server 2016已经原生支持Docker了,其windows Con ...
随机推荐
- MySQL中date类型的空值0000-00-00和00:00:00
1.如果mysql中使用了date类型,并且默认值为'0000-00-00', 那么数据库中的'0000-00-00 00:00:00', '0000-00-00', '00:00:00'这三个值是相 ...
- 多表连接的三种方式详解 HASH JOIN MERGE JOIN NESTED LOOP
在多表联合查询的时候,如果我们查看它的执行计划,就会发现里面有多表之间的连接方式. 之前打算在sqlplus中用执行计划的,但是格式看起来有点乱,就用Toad 做了3个截图. 从3张图里我们看到了几点 ...
- layer 中的 layer.alert layer.msg layer.confirm
1.layer.alert layer.alert('见到你真的很高兴', {icon: 6}); 效果图 layer.alert('墨绿风格,点击确认看深蓝', { skin: 'layui-lay ...
- 在C#使用文件监控对象FileSystemWatcher 实现数据同步
最近在项目中有这么个需求,就是得去实时获取某个在无规律改变的文本文件中的内容.首先想到的是用程序定期去访问这个文件,因为对实时性要求很高,间隔不能超过1S,而且每次获取到文本内容都要去分发给WEB服务 ...
- 扩展jquery插件的方式
- Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
sudo chown -R username /usr/local/lib/node_modules 注:username要具有/usr/local/lib/node_modules的读写权限
- SqlSerVer 列与逗号分隔字符串 互相转换
在项目中,使用SQLServer数据库,有一个需求,需要将数据库的某一列,转换成逗号分隔的字符串.同时,需要将处理完的字符串,转换成为一列. 经过查阅资料与学习,通过以下方式可以实现如上所述需求: 1 ...
- [日常] Go语言圣经-查找重复行
从标准输入中读取数据 1.if语句条件两边也不加括号,但是主体部分需要加{} 2.map存储了键/值(key/value)的集合,对集合元素,提供常数时间的存.取操作,map[string]int = ...
- Java基础教程(18)--继承
一.继承的概念 继承是面向对象中一个非常重要的概念,使用继承可以从逻辑和层次上更好地组织代码,大大提高代码的复用性.在Java中,继承可以使得子类具有父类的属性和方法或者重新定义.追加属性和方法. ...
- 为 HTTP/2 头压缩专门设计的 HPACK
HTTP/2 对消息头采用 HPACK 进行压缩传输,能够节省消息头占用的网络的流量.如何理解 HPACK 压缩呢? 如果我们约定将常用的请求头的参数用一些特殊的编号来表示,比如 GET ...