環境
- Windows 10 Pro 20H2 19042.630
- .NET Framework 4.8 Dev Pack
- Visual Studio Community 2019
- Docker Desktop for Windows 2.5.0.1 (49550) / Windows Container
- Windows Server Core:20H2のDockerイメージ
Windows Server Core:20H2のDockerイメージで.NET Frameworkのバージョンを調べるツールを実行する
Windows Server Core:20H2のDockerイメージを取得する。
Container Base ImageからWindows Server Coreを選択する。タグがltsc2019と20H2の2つあるので20H2を選択する。Full Tag Listingにある20H2-amd64を試す。
$ cd D:\var\workspace\github\DotNetVersions $ docker pull mcr.microsoft.com/windows/servercore:20H2-amd64
イメージのサイズは4.63GBになっている。

Dockerfileを作成する。
D:\var\workspace\github\DotNetVersions\Dockerfile
FROM mcr.microsoft.com/windows/servercore:20H2-amd64 WORKDIR /app COPY ./bin/Release . CMD [ "cmd", "/S", "/C", "C:\\app\\DotNetVersions.exe", "-b" ]
Dockerイメージをビルドする。
$ cd D:\var\workspace\github\DotNetVersions $ docker build --tag windowsservercore20h2-amd64:dotnetversions .

Dockerイメージをコンテナとして実行する。"--detach"オプションでバックグラウンド実行にすると出力が表示されない。
$ cd D:\var\workspace\github\DotNetVersions $ docker run --name WindowsServerCore-20H2-amd64-DotNetVersions windowsservercore20h2-amd64:dotnetversions 4.0.0.0 4.8.04084
参考情報
- Switch between Windows and Linux containers | Docker Desktop for Windows user manual | Docker Documentation
- Get started: Prep Windows for containers | Microsoft Docs
- Windows Container Base Images | Microsoft Docs
- Windows Server Core | Docker Hub
- Long-Term Servicing Channel (LTSC) | Windows Server Servicing channels | Microsoft Docs
- Semi-Annual Channel | Windows Server Servicing channels | Microsoft Docs
- Sample Dockerfile | Build and run your image | Docker Documentation
- Run your image as a container | Build and run your image | Docker Documentation