Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restart a Windows container

I'm trying to run a legacy ASP.Net (.Net 4.7.1) application from a Windows container. One of the requirements is to have the system culture, locale and location set to en-GB. I'm not allowed to touch the code, only the web.config if absolutely needed.

In consideration is the following approach:

  1. create a base image containing all certificates, and culture setting applied (restart is required)
  2. restart base image (either using Windows restart or Container restart, whatever works)
  3. run the base image to ensure the culture settings are correctly applied
  4. save base image
  5. create a new image containing my application, using the base image previously generated

Dockerfile of my base image is:

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

Then build and run the container.

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

Unfortunately, the container either ignores the Restart does not not completely successfully. When I run Get-WinSystemLocale inside the container "en-US" is always returned.

TL,DR: What is the correct way to restart a Windows Container?

I'm using the following container mcr.microsoft.com/dotnet/framework/aspnet:4.7.2

Additional notes regarding failures while setting language pack https://github.com/sanguedemonstro/docker-playground/blob/master/langpack-on-servercore2019.md

Thanks

like image 959
John Louros Avatar asked Apr 01 '19 17:04

John Louros


1 Answers

You really aren't supposed to use Restart-Computer inside you container.

If you need to restart it, you don't even need to spawn a shell inside you container.

First, you need to find your container id. To find container, you can use the docker ps command from a host terminal.

When you have your container id, just run the docker restart {containerId} command.


To change the culture, you can use the globalization tag in your web,config like so.

<system.web>
    <globalization culture="en-GB" uiCulture="en-GB" />
</system.web>
like image 88
Justin Lessard Avatar answered Oct 13 '22 20:10

Justin Lessard