【问题标题】:Mounting Azure File Storage on a Windows Docker container在 Windows Docker 容器上装载 Azure 文件存储
【发布时间】:2020-08-12 16:39:17
【问题描述】:

我有一个在 Azure 中运行的 Windows 容器,我正在尝试将持久性存储附加到该容器,但是,我找不到任何有关如何执行此操作的文档。

Dockerfile:

FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8-20190910-windowsservercore-ltsc2016
SHELL ["powershell"]
EXPOSE 443
WORKDIR /CompanyAPP
COPY WebPackage.zip .
RUN Expand-Archive WebPackage.zip . ; `
    Rename-Item ./CustomerWebConfigurator ./WebConfigurator; `
    Rename-Item ./Customer ./WebRoot; `
    Rename-Item ./CustomerWebService ./WebService; `
    Rename-Item ./CustomerWCFService ./WCFService; `
    rm WebPackage.zip
ARG BUILD
RUN Add-WindowsFeature Net-WCF-HTTP-Activation45;`
    Install-PackageProvider -Name Nuget -Force;`
    Set-PSRepository -Name PSGallery -InstallationPolicy Trusted;`
    Install-Module -Name AWSPowerShell;`
    New-WebApplication -Site 'Default Web Site' -Name 'App' -PhysicalPath c:\CompanyAPP\WebRoot; `
    New-WebApplication -Site 'Default Web Site' -Name 'AppWebService' -PhysicalPath c:\CompanyAPP\WebService; `
    New-WebApplication -Site 'Default Web Site' -Name 'AppWCFService' -PhysicalPath c:\CompanyAPP\WCFService; `
    New-WebApplication -Site 'Default Web Site' -Name 'AppWebConfigurator' -PhysicalPath c:\CompanyAPP\WebConfigurator; `
    Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters' -Name ServerPriorityTimeLimit -Value 0 -Type DWord;`
    $cert = New-SelfSignedCertificate -Subject self; `
    New-WebBinding -Protocol https -port 443 -name 'Default Web Site' -SSLFlags 0; `
    $binding = Get-WebBinding -protocol https; `
    $binding.AddSslCertificate($cert.Thumbprint, 'my');
RUN Set-WebConfiguration -PSPath 'IIS:\Sites\Default Web Site\App' -Filter '/system.web/customErrors' -Value @{mode='Off'};`
    write-host 'got here!'

存储在 Azure 存储帐户中配置,并且使用文件存储,我通过路径映射将其附加到配置中,但没有运气。

希望有人能指出一个好的方向来解决这个问题。

【问题讨论】:

    标签: azure docker windows-container


    【解决方案1】:

    我可能迟到了,但我今天才偶然发现这个问题(即使一年后仍然不支持在 Windows 容器中安装 Azure 文件卷),我发现了一个非常简单的解决方法。我会在这里分享这个,因为这个问题是搜索错误信息时最热门的结果之一。

    您可以通过 SMB 挂载您的 Azure 文件卷。您只需要 UNC、用户名和密码,您可以从 Azure 文件卷的属性中获取这些信息

    所以我创建了一个小的startup.cmd

    @echo off
    net use z: %MNTUNC% %MNTPASS% /user:%MNTUSER%
    "c:\program files\myapp\myapp.exe"
    

    并将startup.cmd定义为dockerfile中的入口点

    ....
    
    COPY ["startup.cmd", "c:/startup.cmd"]
    ENTRYPOINT ["c:/startup.cmd"]
    

    陷阱请注意,使用net use(或New-PSDrive,如果您更喜欢PowerShell)映射的驱动器仅对执行命令的用户帐户可见,因此请确保以相同的用户挂载驱动器,用于执行服务。

    您可以在部署期间设置环境变量的值,如下所述:

    https://docs.microsoft.com/en-us/azure/container-instances/container-instances-environment-variables

    例如,当使用 YAML 文件进行部署时,您可以如下设置环境变量。使用 secureValue 使环境变量的值只能从容器内访问,并且这些值不会显示在 Azure 门户上容器的属性中。

    ....
    containers:
      - name: mycontainer
        properties:
          environmentVariables:
            - name: 'MNTUNC'
              secureValue: '\\myaccountname.file.core.windows.net\myvolume'
            - name: 'MNTPASS'
              secureValue: 'mysupersecretpassword'
            - name: 'MNTUSER'
              secureValue: 'Azure\myaccountname'
    

    【讨论】:

    • 在 WinOS Server Core LTS 2019 上使用 Azure Container Instances 尝试了这种方法 - 运气不好 => 401 Unauthorized 在尝试从容器内访问 Azure File Share Premium 时 - 可能与我们如何使用它有关......我们是using self-hosted build agent in Docker,也尝试使用New-PSDriveNew-SmbGlobalMapping - 没有骰子!
    • @SliverNinja-MSFT 您是否能够使用相同的 UNC + 凭据从(例如)本地系统挂载文件共享? Unauthorized 听起来更像是凭据问题。您能否尝试在启动时回显环境变量并检查容器的日志是否正确?
    • 伟大的标注,Unauthorized 是一个错误 - 凭据无效 - 使用您建议的诊断输出很明显! ? 我测试了对 Azure Files SMB 的直接读/写,它运行良好!下一个障碍似乎是使用child process run from powershell.exe launching Agent.Listener.exe 限制对共享的访问,azure 管道使用它来启动构建代理(通过run.cmd)。任何想法如何使这个共享对容器内的另一个工作进程可见?
    • 抱歉,对那个特定用例一​​无所知。但如上所述,映射的网络驱动器仅对映射它们的用户帐户可见。也许那个东西在Windows服务帐户下运行?那么这个答案可能会对你有所帮助serverfault.com/questions/4623/…
    • @SliverNinja-MSFT 这也可能有助于powershellmagazine.com/2015/04/08/…
    【解决方案2】:

    如果您使用 Azure 容器实例部署 Windows 容器,则 Azure 文件存储不支持持久卷。目前仅限于 Linux 容器。您可以获取有关注释here的更多详细信息:

    装载 Azure 文件共享当前仅限于 Linux 容器。

    更新:

    根据评论中提供的消息,您可以将 Web 应用程序用于具有 Windows 映像的容器。在这种情况下,它支持将 Azure 文件共享挂载到 Windows 容器。您可以按照Configure Azure Files in a Windows Container on App Service 中的步骤进行操作。

    【讨论】:

    • 你好,查尔斯。我实际上正在使用容器的 Web 应用程序来托管所述容器,以试图找出解决此问题的方法 - 希望这是可能的。
    • @devopsidiot 哇,您需要在问题的开头添加此消息。我会更新答案。
    • @devopsidiot 还有问题吗?它解决了你的问题吗?如果它适合你,请接受它作为答案。
    猜你喜欢
    • 2017-11-26
    • 2021-01-31
    • 2015-04-24
    • 2020-06-29
    • 1970-01-01
    • 2020-11-28
    • 1970-01-01
    • 1970-01-01
    • 2020-12-29
    相关资源
    最近更新 更多