如何重新启动Windows容器

时间:2019-04-01 17:10:53

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

我正在尝试从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

不幸的是,容器要么忽略了重新启动未完全成功。当我在容器内运行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时失败的其他说明

谢谢

2 个答案:

答案 0 :(得分:2)

您实际上不应该在容器内使用Restart-Computer

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

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

拥有容器ID后,只需运行docker restart {containerId} command


要更改文化,您可以像这样在Web,config中使用全球化标签。

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

答案 1 :(得分:1)

如果您使用的是Powershell,则可以尝试使用this solution来安全重启Windows容器。