上一节中,我们已经准备好了 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. springboot-4-整合fastjson

    使用fastjson作为springboot的默认json解析, 原来使用的是jackson 1, 引入依赖 <dependencies> <dependency> <g ...

  2. Linux-(chgrp,chown,chmod)

    /etc/group Linux /etc/group文件与/etc/passwd和/etc/shadow文件都是有关于系统管理员对用户和用户组管理时相关的文件. Linux /etc/group文件 ...

  3. 桌面程序开发入门(WinForm with C#)

    1.使用Visual Studio 2013创建新项目 2.创建一个主窗体和4个子窗体 3.创建一个数据库.一个表.一个存储过程 4.在配置文件里添加数据库连接字符串 5.真正的编码工作. 第一步:创 ...

  4. NoSQL数据库--简介

    一.What's NoSQL? NoSQL,全称是”Not Only Sql”,指的是非关系型的数据库.这类数据库主要有这些特点:非关系型的.分布式的.开源的.水平可扩展的.原始的目的是为了大规模we ...

  5. Linux的用户(组),权限,文件精妙的三角关系,和强大的帮助系统

    在linux中一切都是文件(文件夹和硬件外设是特殊的文件),如果有可能尽量使用文本文件.文本文件是人和机器能理解的文件,也成为人和机器进行 交流的最好途径.由于所有的配置文件都是文本,所以你只需要一个 ...

  6. redis集群与分片(1)-redis服务器集群、客户端分片

    下面是来自知乎大神的一段说明,个人觉得非常清晰,就收藏了. 为什么集群? 通常,为了提高网站响应速度,总是把热点数据保存在内存中而不是直接从后端数据库中读取.Redis是一个很好的Cache工具.大型 ...

  7. bzoj 3600: 没有人的算术

    Description Solution 我们可以给每一个数钦定一个权值 , 这样就可以 \(O(1)\) 比较大小了. 考虑怎么确定权值: 用平衡树来维护 , 我们假设根节点管辖 \([1,2^{6 ...

  8. [转]WebForm中使用MVC

    本文转自:https://www.cnblogs.com/encoding/articles/3556046.html 前言 掐指一算,3年没写博了,好懒的说... 众所周知,MVC现在越来越火了,不 ...

  9. mongodb int型id 自增

    mongo的c#客户端提供了接口IIdGenerator,有guid和objectid等几种实现,但没有int型id的实现 接口主要2个方法,一个IsEmpty返回bool,判断当前id值是否是空(估 ...

  10. C# 中 NPOI 库读写 Excel 文件的方法【摘】

    原作:淡水网志 NPOI 是开源的 POI 项目的.NET版,可以用来读写Excel,Word,PPT文件.在处理Excel文件上,NPOI 可以同时兼容 xls 和 xlsx.官网提供了一份 Exa ...