问题
I'm creating a docker container based on the mcr.microsoft.com/dotnet/framework/runtime:4.8 base image.
This image is set to en_US, meaning that all the Windows language and region settings and default location is set to United States.
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:
- Attempted to use the
intl.cplInternational 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
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>
- Setting the values before starting the application in a
powershellscript:
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
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
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?
回答1:
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
Now run Docker:
docker run -it --isolation=process mcr.microsoft.com/windows/servercore:1909 PowerShell
Within the Docker shell:
Get-WinSystemLocale
LCID Name DisplayName
---- ---- -----------
2057 en-GB English (United Kingdom)
来源:https://stackoverflow.com/questions/58168226/setting-the-language-and-region-settings-in-a-windows-docker-container