【问题标题】:How to restart a Windows container如何重新启动 Windows 容器
【发布时间】:2019-04-01 17:10:52
【问题描述】:

我正在尝试从 Windows 容器运行旧版 ASP.Net (.Net 4.7.1) 应用程序。要求之一是将系统文化、区域设置和位置设置为 en-GB。我不允许触碰代码,如果绝对需要,只能触碰 web.config。

考虑以下方法:

  1. 创建包含所有证书的基础映像,并应用文化设置(需要重新启动)
  2. 重新启动基础映像(无论是使用 Windows 重新启动还是容器重新启动,都可以)
  3. 运行基础映像以确保正确应用区域性设置
  4. 保存基础图片
  5. 使用之前生成的基础映像创建一个包含我的应用程序的新映像

我的基础镜像的 Dockerfile 是:

FROM mcr.microsoft.com/dotnet/framework/aspnet:4.7.2
ARG site_root=.
WORKDIR /scripts
COPY scripts/ .

RUN powershell -f install-certificates.ps1

RUN powershell C:/Windows/System32/inetsrv/appcmd.exe set config /commit:WEBROOT /section:globalization /culture:en-GB
RUN powershell C:/Windows/System32/inetsrv/appcmd.exe set config /commit:WEBROOT /section:globalization /uiCulture:en-GB

RUN powershell Set-Culture en-GB
RUN powershell Set-WinSystemLocale en-GB
RUN powershell Set-WinHomeLocation -GeoId 242
RUN powershell Set-WinUserLanguageList en-GB -Force

然后构建并运行容器。

docker build -t tmpaspnet .
docker run -it --name tmpcontainer --entrypoint powershell tmpaspnet
# inside the container
Restart-Computer
# container will exit, wait a few seconds
docker start tmpcontainer
docker exec tmpcontainer powershell Get-WinSystemLocale
# verify if system locale is correct set
# commit changes and save them to a new image
docker commit -m 'set system locale to en-GB' tmpcontainer myrepo/aspnet:latest

很遗憾,容器要么忽略Restart,要么没有完全成功。当我在容器内运行Get-WinSystemLocale 时,总是返回“en-US”。

TL,DR:重启 Windows 容器的正确方法是什么?

我正在使用以下容器 mcr.microsoft.com/dotnet/framework/aspnet:4.7.2

关于设置语言包时失败的附加说明https://github.com/sanguedemonstro/docker-playground/blob/master/langpack-on-servercore2019.md

谢谢

【问题讨论】:

  • 你在这方面有什么收获吗?我也在寻找重新启动来宾操作系统的解决方案;似乎 docker 在操作系统重启期间中断了某些事情,所以它没有正确完成
  • 不幸的是没有基思。此问题尚无解决方案
  • stackoverflow.com/questions/43581001/… 这个答案可能可以帮助您解决最初的问题:更改容器内部的默认区域性。

标签: docker docker-for-windows windows-container


【解决方案1】:

你真的不应该在你的容器中使用Restart-Computer

如果您需要重新启动它,您甚至不需要在容器内生成 shell。

首先,您需要找到您的容器 ID。要查找容器,您可以从主机终端使用docker ps command

获得容器 ID 后,只需运行 docker restart {containerId} command


要改变文化,你可以在你的网页中使用全球化标签,像这样配置。

<system.web>
    <globalization culture="en-GB" uiCulture="en-GB" />
</system.web>

【讨论】:

  • 很遗憾docker restart {containerId} 不起作用。运行 docker exec tmpcontainer powershell Get-WinSystemLocale 仍然返回“en-US”。这可能是容器操作系统的限制。
  • 除此之外,应用程序似乎忽略了&lt;system.web&gt; &lt;globalization culture="en-GB" uiCulture="en-GB" /&gt; &lt;/system.web&gt; :(
【解决方案2】:

如果您使用的是 powershell,您可以尝试this solution,它应该可以安全地重新启动 Windows 容器。

【讨论】:

  • 那个解决方案有点矫枉过正 :) 不幸的是,它也不起作用。
猜你喜欢
  • 1970-01-01
  • 2020-01-21
  • 2017-01-10
  • 1970-01-01
  • 1970-01-01
  • 2016-09-16
  • 1970-01-01
  • 2018-05-16
  • 1970-01-01
相关资源
最近更新 更多