在 Windows Docker 容器中设置语言和区域设置

Setting the language and region settings in a Windows Docker Container(在 Windows Docker 容器中设置语言和区域设置)

本文介绍了在 Windows Docker 容器中设置语言和区域设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个基于 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 的第 3 方库上.但是到目前为止,我尝试过的任何东西似乎都无法更改语言和区域设置.

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:

  1. 尝试使用 intl.cpl 国际设置导入设置并更新默认用户:
  1. Attempted to use the intl.cpl International Settings to import the settings and update the default user:

# Set Locale and language 
& $env:SystemRootSystem32control.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>

  1. powershell 脚本中启动应用程序之前设置值:
  1. 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 外壳中:

Within the Docker shell:

Get-WinSystemLocale

LCID             Name             DisplayName
----             ----             -----------
2057             en-GB            English (United Kingdom)

这篇关于在 Windows Docker 容器中设置语言和区域设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:在 Windows Docker 容器中设置语言和区域设置

基础教程推荐