dev*_*iot 2 azure docker windows-container
我有一个在 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!'
Run Code Online (Sandbox Code Playgroud)
存储是在 Azure 存储帐户中配置的,并使用文件存储,我通过路径映射将其附加到配置中,但运气不佳。
希望有人能给我指出一个好的方向来解决这个问题。
我可能来晚了,但直到今天我才偶然发现这个问题(一年后仍然不支持在 Windows 容器中安装 Azure 文件卷),并且我找到了一个相当简单的解决方法。我将在这里分享这个问题,因为这个问题是搜索错误消息时最重要的结果之一。
您可以通过 SMB 挂载 Azure 文件卷。您所需要的只是 UNC、用户名和密码,您可以从 Azure 文件卷的属性中获取这些信息
所以我创建了一个小startup.cmd
@echo off
net use z: %MNTUNC% %MNTPASS% /user:%MNTUSER%
"c:\program files\myapp\myapp.exe"
Run Code Online (Sandbox Code Playgroud)
并将其定义startup.cmd为中的入口点dockerfile
....
COPY ["startup.cmd", "c:/startup.cmd"]
ENTRYPOINT ["c:/startup.cmd"]
Run Code Online (Sandbox Code Playgroud)
陷阱:请注意,使用net use(或者New-PSDrive如果您更喜欢 PowerShell)映射的驱动器仅对执行命令的用户帐户可见,因此请务必使用用于执行服务的同一用户挂载驱动器。
您可以在部署期间设置环境变量的值,如下所述:
例如,使用YAML文件进行部署时,可以按如下方式设置环境变量。使用secureValue使得环境变量的值只能从容器内访问,并且这些值不会显示在例如天蓝色门户上的容器属性中。
....
containers:
- name: mycontainer
properties:
environmentVariables:
- name: 'MNTUNC'
secureValue: '\\myaccountname.file.core.windows.net\myvolume'
- name: 'MNTPASS'
secureValue: 'mysupersecretpassword'
- name: 'MNTUSER'
secureValue: 'Azure\myaccountname'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3330 次 |
| 最近记录: |