在Windows Docker容器中设置语言和区域设置 [英] Setting the language and region settings in a Windows Docker Container
问题描述
我正在基于 mcr.microsoft.com/dotnet/framework/runtime:4.8
基本映像创建一个Docker容器。
I'm creating a docker container based on the mcr.microsoft.com/dotnet/framework/runtime:4.8
base image.
此图像设置为 en_US
,表示所有Windows语言和区域设置以及默认位置均设置为美国。
This image is set to en_US
, meaning that all the Windows language and region settings and default location is set to United States.
我需要做的是将其更改为 en_GB
并将位置更改为 United Kindom
作为默认用户,因为我有一个.Net应用程序,该应用程序依赖于第三方库,该库使用此库将数据输出到Excel。但是,到目前为止,我尝试过的所有操作似乎都无法更改语言和区域设置。
What I need to do is to change this to en_GB
and change the location to United Kindom
for the default user because I have a .Net application which has a dependency on a 3rd party library that uses this to output data to Excel. However nothing I've tried seems to be able to change the language and region settings thus far.
到目前为止,我已经尝试过:
Things I have tried so far:
- 尝试使用
intl.cpl
国际设置以导入设置并更新默认用户:
- Attempted to use the
intl.cpl
International Settings to import the settings and update the default user:
# Set Locale and language
& $env:SystemRoot\System32\control.exe "intl.cpl,,/f:`"UKRegion.xml`""
# Set Languages/culture
Set-Culture en-GB
UKRegion.xml的内容:
Contents of UKRegion.xml:
<gs:GlobalizationServices xmlns:gs="urn:longhornGlobalizationUnattend">
<!--User List-->
<gs:UserList>
<gs:User UserID="Current" CopySettingsToDefaultUserAcct="true" CopySettingsToSystemAcct="true"/>
</gs:UserList>
<!-- user locale -->
<gs:UserLocale>
<gs:Locale Name="en-GB" SetAsCurrent="true"/>
</gs:UserLocale>
<!-- system locale -->
<gs:SystemLocale Name="en-GB"/>
<!-- GeoID -->
<gs:LocationPreferences>
<gs:GeoID Value="242"/>
</gs:LocationPreferences>
<gs:MUILanguagePreferences>
<gs:MUILanguage Value="en-GB"/>
<gs:MUIFallback Value="en-US"/>
</gs:MUILanguagePreferences>
<!-- input preferences -->
<gs:InputPreferences>
<!--en-GB-->
<gs:InputLanguageID Action="add" ID="0809:00000809" Default="true"/>
</gs:InputPreferences>
</gs:GlobalizationServices>
- 在启动应用程序之前在
powershell
脚本:
- Setting the values before starting the application in a
powershell
script:
Set-WinSystemLocale -SystemLocale en-GB
Set-WinHomeLocation -GeoId 242
Set-WinUserLanguageList -LanguageList (New-WinUserLanguageList -Language en-GB) -Force
Set-Location -Path "C:\\AppFolder"
.\AppExe.exe
设置容器并附上我可以看到 Get-WinHomeLocation
已更新, Get-WinUserLanguageList
显示 en_GB
作为选项,但是 Get-WinSystemLocale
中Windows的默认语言仍返回 en-US
After setting up the container and attaching I can see that Get-WinHomeLocation
has updated, Get-WinUserLanguageList
shows en_GB
as an option, however the default language for windows from Get-WinSystemLocale
still returns en-US
我还考虑过从en-GB Windows Server Core基本映像构建自己的基本映像,并运行Microsoft运行的框架设置以创建Framework runtime 4.8映像,但是Microsoft似乎没有发布en-GB基本映像!
I also considered building my own base image from the en-GB Windows Server Core base image and running the framework setup that Microsoft runs to create the Framework runtime 4.8 image, but Microsoft don't seem to publish an en-GB base image!
还有其他人遇到吗?您是如何解决的?还有其他建议吗?
Has anyone else come across this? How did you resolve it? Any other suggestions?
推荐答案
答案是,Docker容器在使用进程隔离时会从主机继承语言设置。因此,请根据需要更改主持人的语言设置。在PowerShell中,要设置区域,您可以执行以下操作:
The answer is that a Docker container inherits language settings from the host when using Process Isolation. So, change the host's language settings as desired. In PowerShell, to set the Region you can do this:
Set-WinSystemLocale en-GB
Restart-Computer
现在运行Docker:
Now run Docker:
docker run -it --isolation=process mcr.microsoft.com/windows/servercore:1909 PowerShell
在Docker Shell中:
Within the Docker shell:
Get-WinSystemLocale
LCID Name DisplayName
---- ---- -----------
2057 en-GB English (United Kingdom)
这篇关于在Windows Docker容器中设置语言和区域设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!