上一节中,我们已经准备好了 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. C++中模板与泛型编程

    目录 定义一个通用模板 模板特化和偏特化 模板实例化与匹配 可变参数模板 泛型编程是指独立与任何类型的方式编写代码.泛型编程和面向对象编程,都依赖与某种形式的多态.面向对象编程的多态性在运行时应用于存 ...

  2. HTML引入CSS样式的四种方法

    在HTML中引入CSS的方法主要有四种,它们分别是行内式.内嵌式.链接式和导入式. 1.行内式          行内式是在标记的style属性中设定CSS样式.这种方式没有体现出CSS的优势,不推荐 ...

  3. Java 裁剪图片

    package com.test; import java.awt.image.BufferedImage; import java.io.File; import javax.imageio.Ima ...

  4. 修改MVC默认的pageBaseType以添加功能

    试想下在MVC的前端页面JS或者html中需要使用多语言,而后端的多语言是维护在资源文件中的,前端如果使用的话需要使用AJAX频繁的获取,一个页面中可能会存在大量的需要语言转换的地方,频繁使用AJAX ...

  5. Mybatis中同时使用shardbatis和pagehelper插件冲突问题

    在一次使用mybatis的插件,分表shardbatis+分页pagehelper共同使用的时候,会抛出以下异常: java.lang.NoSuchMethodError: net.sf.jsqlpa ...

  6. linux 权限详解

    转载自博客园: http://www.cnblogs.com/123-/p/4189072.html 用户组 在linux中的每个用户必须属于一个组,不能独立于组外.在linux中每个文件有所有者.所 ...

  7. 【转】Js获取当前日期时间及其它操作

    Js获取当前日期时间及其它操作 原文地址:http://www.cnblogs.com/carekee/articles/1678041.html var myDate = new Date();my ...

  8. Eclipse下安装SVN插件以及连接SVN服务并发布项目

    Eclipse安装SVN插件 Help->Eclipse MarketPlace 查找并安装Subclipse插件 按默认步骤完成SVNEclipse插件的安装(安装完成后需要重启Eclipse ...

  9. Java基础教程(16)--注解

    一.注解基础知识 1.注解的格式   最简单的注解就像下面这样: @Entity   @符号指示编译器其后面的内容是注解.在下面的例子中,注解的名称为Override: @Override void ...

  10. Eclipse中新建Java工程的三个JRE选项区别

    整理自:https://blog.csdn.net/wdjhzw/article/details/42086615 官方解释(链接) Use default JRE: When selected, t ...