.NET RuntimeのDockerイメージに含まれる.NETのバージョンを調べる

2020年11月29日(日)

環境

.NET SDK 5.0をホスト環境にインストールする

Download .NETから.NET SDK x64をダウンロードする。

Download .NET

.NET SDK x64のインストーラーを実行する。

dotnet-sdk-5.0.100-win-x64.exe

.NETのバージョンを確認する。

$ dotnet --version
5.0.100
        

参考情報

.NET RuntimeのDockerイメージで.NETのバージョンを調べる

.NET RuntimeのDockerイメージを取得する。

Container Base ImageNano Serverの説明には次のようにある。

Built for .NET Core applications.

Nano ServerのDockerイメージには.NETは含まれていない。

.NETのDockerイメージ > .NET RuntimeのDockerイメージを辿って"Windows Server, version 2009 amd64 Tags"から.NET Runtimeを含むNano ServerのDockerイメージを取得する。

$ cd C:\Temp\dotnet
$ docker pull mcr.microsoft.com/dotnet/runtime:5.0.0-nanoserver-2009
        

イメージのサイズは332.12MBになっている。

mcr.microsoft.com/dotnet/runtime:5.0.0-nanoserver-2009

Dockerfileを作成する。

C:\Temp\dotnet\DotNetVersions\Dockerfile
FROM mcr.microsoft.com/dotnet/runtime:5.0.0-nanoserver-2009
WORKDIR /app
CMD [ "cmd", "/S", "/C", "dir", "C:\\" ]
          

Dockerイメージをビルドする。

$ cd C:\Temp\dotnet\DotNetVersions
$ docker build --tag net-5-nano-2009-amd64:dotnetversions .
        
.NET Runtime 5.0.0 Nano Server 2009 amd64 | DotNetVersions

Dockerイメージをコンテナとして実行する。"--detach"オプションでバックグラウンド実行にすると出力が表示されない。

$ cd C:\Temp\dotnet\DotNetVersions
$ docker run --name Net-5-Nano-2009-amd64-DotNetVersions net-5-nano-2009-amd64:dotnetversions
Volume in drive C has no label.
Volume Serial Number is 86DC-120F

Directory of C:\

11/27/2020  08:20 PM    <DIR>          app
11/06/2020  07:09 PM             5,510 License.txt
11/11/2020  03:16 AM    <DIR>          Program Files
11/06/2020  07:11 PM    <DIR>          Users
11/11/2020  03:15 AM    <DIR>          Windows
              1 File(s)          5,510 bytes
              4 Dir(s)  21,303,574,528 bytes free
        

.NETのバージョンの確認方法を参考にしてProgram Files配下を確認する。

C:\
  +-Program Files
      +-dotnet
          |-dotnet.exe
          +-host
          |   +-fxr
          |       +-5.0.0
          |           |-hostfxr.dll
          |-LICENSE.txt
          +-shared
          |   +-Microsoft.NETCore.App
          |       +-5.0.0
          |-ThirdPartyNotices.txt
        

"dotnet"コマンドが入っているのでそれを使って.NETのバージョンを確認する。

Dockerfileを作成する。

C:\Temp\dotnet\DotNetVersions\Dockerfile
FROM mcr.microsoft.com/dotnet/runtime:5.0.0-nanoserver-2009
WORKDIR /app
CMD [ "cmd", "/S", "/C", "dotnet", "--version" ]
          

Dockerイメージをビルドする。

$ cd C:\Temp\dotnet\DotNetVersions
$ docker build --tag net-5-nano-2009-amd64:dotnetversions .
        

Dockerイメージをコンテナとして実行する。"--detach"オプションでバックグラウンド実行にすると出力が表示されない。

$ cd C:\Temp\dotnet\DotNetVersions
$ docker run --name Net-5-Nano-2009-amd64-DotNetVersions net-5-nano-2009-amd64:dotnetversions
Could not execute because the application was not found or a compatible .NET SDK is not installed.
Possible reasons for this include:
  * You intended to execute a .NET program:
      The application '--version' does not exist.
  * You intended to execute a .NET SDK command:
      It was not possible to find any installed .NET SDKs.
      Install a .NET SDK from:
        https://aka.ms/dotnet-download
        

C:\Program Files\dotnet\dotnet.exeはSDKのCLIではないのでバージョンの確認はできない。

C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.0がバージョンになる。

参考情報

.NET RuntimeのDockerイメージのフォルダ構造を確認する

C:\
  |-License.txt
  |
  +-Program Files
  |   +-dotnet
  |       |-dotnet.exe
  |       +-host
  |       |   +-fxr
  |       |       +-5.0.0
  |       |           |-hostfxr.dll
  |       |-LICENSE.txt
  |       +-shared
  |       |   +-Microsoft.NETCore.App
  |       |       +-5.0.0
  |       |-ThirdPartyNotices.txt
  |
  +-Users
  |   +-ContainerAdministrator (File Not Found)
  |   +-ContainerUser (空フォルダ)
  |   +-Public (空フォルダ)
  |
  +-Windows
      +-AppCompat
      +-apppatch
      +-Branding
      +-DiagTrack
      +-Globalization
      +-INF
      +-L2Schemas
      +-LiveKernelReports
      +-PolicyDefinitions
      +-ServiceProfiles
      +-ServiceState
      +-System32
      +-SystemResources
      +-SysWOW64
      +-Temp
      +-WaaS