Windows Server 2019 で
Container を使ってみる
.NETラボ 勉強会 2018年10月 ~インフラを学ぶ1日~ (2018.10.20)
Kazuki Takai
自己紹介
 高井 一輝 (Takai Kazuki)
 某ISP勤務
 クラウドサービスの開発、設計、設備維持
 Windows Server / System Center / Linux / etc…
 Microsoft MVP - Cloud and Datacenter Management
 System Center User Group Japan (SCUGJ)
 Twitter : @zhuky7 / Facebook : kazuki.takai
 Blog : http://operationslab.wordpress.com/
セッションの内容とゴール
 お話しすること
 Container とは
 Windows Server の Container 機能
 Windows Server 2019 で Container を使う
 お話ししないこと
 Container のオーケストレーション
 ゴール
 Windows Server 2019 で Container を使ってみることができる
Agenda
 Containers とは
 Windows Server の Containers
 Containers を使う
 なるべくデモ中心で…
はじめる前に
 本資料の内容は個人的な検証結果に基づきます
 所属する会社や組織、マイクロソフト社の公式な見解を記載するものではありません
 表記や内容に誤りがあるなど、お気づきの点があれば、ご連絡いただけると幸いです
 本セッションでは、以下の環境をベースにお話しします
 Windows Server 2019 LTSC Build 17763.55 + Docker 18.03.1-ee-3
Containers とは
 コンテナーとは
 コンテナーとは、分離された独自のボックスにアプリケーションをラップする方法で
す。 コンテナー内のアプリケーションは、ボックスの外に存在するアプリケーション
やプロセスを認識しません。 コンテナー内には、アプリケーションの正常な実行に必
要なすべての要素も存在します。 ボックスを移動しても、アプリケーションの実行に
必要な要素がすべて揃っているため、アプリケーションが常に正常に実行されます。
 https://docs.microsoft.com/ja-jp/virtualization/windowscontainers/about/
Containers とは
 アプリケーションと、アプリケーションの実行に必要な環境をまとめたもの
 OS ベースの仮想化
 リソース分離
 可搬性
 広義には、App-V なども Containers
 今回お話しするのは Windows Containers
 Docker ベースの Containers 管理機構
Containers と VM の違い
Containers = operating system virtualization Traditional virtual machines = hardware virtualization
OS
Kernel
Applications
Container Container Container
Hardware Hardware
OS
Application
VM VM VM
App
OS
App
OS
App
OS
Containers と VM の違い
 VM (Virtual Machine)
 ハードウェアを仮想化
 OS の実行空間を分離
 Containers
 OS(の一部)を仮想化
 アプリケーションの実行空間を分離
Containers の利点
Fast
iteration
Agile
delivery
Immutability Cost
savings
Elastic
bursting
Efficient
deployment
For ITFor developers
Windows Server の Container
 Windows Server 2016 で初搭載
 Containers の機能を有効化することで利用可能
 一部機能の利用には Hyper-V が必要
 Hyper-V が必要な場合は、サポートするハードウェアが必要
Windows Containers の基本要素
 Container Host
 Windows Containers の機能が有効化された、物理マシン又は VM
 Container Host 上で 1 つ以上の Container を実行する
 Container Image
 ソフトウェア(の一部)を単体で実行可能な形でパッケージングしたもの
 一般的には、軽量
 実行に必要となるコード、ランタイム、ライブラリ、設定、ツール等を含む
 Container OS Image
 OS 環境を提供する Container Image
 全ての Container Image は、Container OS Image を 1st partition として構築される
 Microsoft により提供され、変更不可
 Container Repository
 Container Image を管理するリポジトリ
 Docker Hub や Azure Container Registry 等
2 種類の Container OS Image
 microsoft/windowsservercore
 Windows Server Core ベースのイメージ
 イメージサイズは大きい
 Nano Server をサポートしないアプリケーションや Windows 機能を利用したい場合に使用
 microsoft/nanoserver
 Nano Server ベースのイメージ
 イメージサイズは比較的小さい
 IIS + .NET Core のモダン Web アプリケーションなど、新しいアプリケーション・Containers
環境を意識して設計されたアプリケーションで使用
Container OS Images
2種類の Containers
Windows Server containers: shared kernel Hyper-V isolation: isolated kernel
Hardware
Container Container Container
Hyper-V
Container
Kernel
Container
Kernel
Container
Kernel
2種類の Containers
 Windows Server containers
 通常の(一般的な)Containers
 Container は、ホスト OS の kernel を使用
 Hyper-V containers と比べて軽量(オーバーヘッドが少ない)
 所謂 Linux の Containers と同じ
 Hyper-V containers
 Hyper-V の機能を利用してリソース隔離した Containers
 Container は、独自の OS kernel を使用
 Windows Server containers と比べて、分離レベルが高い(オーバーヘッドは多い)
どちらを使うか?
 今のところは Hyper-V containers を推奨
 Windows Server containers の場合、ホストと Container の OS バージョンに注意
 https://docs.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/version-
compatibility
 Nano Server ベースのイメージを使用するには Hyper-V containers が必要となる
 Linux ベースのイメージを使用する場合も Hyper-V containers が必要となる
 Client containers (Containers on Windows 10) は Hyper-V containers のみサポート
docker run -it --isolation process microsoft/windowsservercore powershell
C:¥Program Files¥Docker¥Docker¥Resources¥bin¥docker.exe: Error response from daemon:
Windows client operating systems only support Hyper-V containers.
Demo
PS> Get-WindowsFeature Hyper-V,Containers | Install-WindowsFeature -
IncludeManagementTools
PS> Restart-Computer
PS> Install-Module -Name DockerProvider -Repository PSGallery -Force
PS> Install-Package -Name docker -ProviderName DockerProvider -
RequiredVersion 18.03 -Force
# Create %programdata%¥docker¥config¥daemon.json
PS> Restart-Service docker
PS> Invoke-WebRequest -Uri
'https://github.com/linuxkit/lcow/releases/download/4.14.29-
0aea33bc/release.zip' -UseBasicParsing -OutFile .¥Downloads¥release.zip
PS> Expand-Archive .¥Downloads¥release.zip -DestinationPath
"$Env:ProgramFiles¥Linux Containers¥."
Prepare Container Hosts
Windows Containers を使う
 Windows Server
 DockerMsftProvider or DockerProvider PS Module をインストール
 docker パッケージをインストール
 再起動
 https://docs.microsoft.com/ja-jp/virtualization/windowscontainers/quick-
start/quick-start-windows-server
 https://docs.microsoft.com/ja-jp/virtualization/windowscontainers/quick-
start/using-insider-container-images
確認ポイント
 docker version
 Client version / Server (docker engine) version
 Experimental
 docker info
 Default Isolation
 Kernel Version
 Experimental
Windows 環境向け Docker client
 (現時点で)Windows 環境向けに特異な docker client option
 --isolation
 分離モードの指定
 --isolation hyperv // クライアント OS のデフォルト
 --isolation process // サーバー OS のデフォルト
 --platform
 (Windows Host 上で)どの OS kernel を使用するかの指定
 --platform=linux // LCOW を使用
 --platform=windows // Windows を使用
Linux containers on Windows hosts
 Windows Host で Linux ベースの Container Image を実行可能
 Windows Server 2016 では利用不可
 Windows Server 1709 以降(ホスト)
 Docker Engine 17.11 以降
 LinuxKit / LCOW (最新の Release を推奨)
Windows Containers の今後
 Container OS Image としての進化
 イメージサイズをより小さく
 Container Host としての進化
 オーケストレーションに注力
 Docker engine / Kubernetes との連携
まとめ
 Windows Containers
 OS virtualization
 Hyper-V isolation
 Containers の使い始め方
 PowerShell 数行で構成可能
 Containers 使ってみてください!
やること
 Windows Server で Container を使うために必要なこと
 Get-WindowsFeature Hyper-V,Containers | Install-WindowsFeature -
IncludeManagementTools
 Restart-Computer
 Install-Module -Name DockerProvider -Repository PSGallery -Force
 Install-Package -Name docker -ProviderName DockerProvider -RequiredVersion
18.03 -Force
やること(オプション)
 Windows Server で Linux Container Image を使うために必要なこと
 Docker Engine の Experimental Support を有効化
 %programdata%¥docker¥config¥daemon.json
 Restart-Service docker
 Invoke-WebRequest -Uri
'https://github.com/linuxkit/lcow/releases/download/4.14.29-
0aea33bc/release.zip' -UseBasicParsing -OutFile .¥release.zip
 Expand-Archive .¥release.zip -DestinationPath "$Env:ProgramFiles¥Linux
Containers¥."
参考資料
 Containers 101 with Microsoft and Docker
 https://channel9.msdn.com/Blogs/containers/Containers-101-with-Microsoft-
and-Docker?ocid=player
 Install Docker Enterprise Edition for Windows Server
 https://docs.docker.com/install/windows/docker-ee/

Windows Server 2019 で Container を使ってみる

  • 1.
    Windows Server 2019で Container を使ってみる .NETラボ 勉強会 2018年10月 ~インフラを学ぶ1日~ (2018.10.20) Kazuki Takai
  • 2.
    自己紹介  高井 一輝(Takai Kazuki)  某ISP勤務  クラウドサービスの開発、設計、設備維持  Windows Server / System Center / Linux / etc…  Microsoft MVP - Cloud and Datacenter Management  System Center User Group Japan (SCUGJ)  Twitter : @zhuky7 / Facebook : kazuki.takai  Blog : http://operationslab.wordpress.com/
  • 3.
    セッションの内容とゴール  お話しすること  Containerとは  Windows Server の Container 機能  Windows Server 2019 で Container を使う  お話ししないこと  Container のオーケストレーション  ゴール  Windows Server 2019 で Container を使ってみることができる
  • 4.
    Agenda  Containers とは Windows Server の Containers  Containers を使う  なるべくデモ中心で…
  • 5.
    はじめる前に  本資料の内容は個人的な検証結果に基づきます  所属する会社や組織、マイクロソフト社の公式な見解を記載するものではありません 表記や内容に誤りがあるなど、お気づきの点があれば、ご連絡いただけると幸いです  本セッションでは、以下の環境をベースにお話しします  Windows Server 2019 LTSC Build 17763.55 + Docker 18.03.1-ee-3
  • 6.
    Containers とは  コンテナーとは コンテナーとは、分離された独自のボックスにアプリケーションをラップする方法で す。 コンテナー内のアプリケーションは、ボックスの外に存在するアプリケーション やプロセスを認識しません。 コンテナー内には、アプリケーションの正常な実行に必 要なすべての要素も存在します。 ボックスを移動しても、アプリケーションの実行に 必要な要素がすべて揃っているため、アプリケーションが常に正常に実行されます。  https://docs.microsoft.com/ja-jp/virtualization/windowscontainers/about/
  • 7.
    Containers とは  アプリケーションと、アプリケーションの実行に必要な環境をまとめたもの OS ベースの仮想化  リソース分離  可搬性  広義には、App-V なども Containers  今回お話しするのは Windows Containers  Docker ベースの Containers 管理機構
  • 8.
    Containers と VMの違い Containers = operating system virtualization Traditional virtual machines = hardware virtualization OS Kernel Applications Container Container Container Hardware Hardware OS Application VM VM VM App OS App OS App OS
  • 9.
    Containers と VMの違い  VM (Virtual Machine)  ハードウェアを仮想化  OS の実行空間を分離  Containers  OS(の一部)を仮想化  アプリケーションの実行空間を分離
  • 10.
  • 11.
    Windows Server のContainer  Windows Server 2016 で初搭載  Containers の機能を有効化することで利用可能  一部機能の利用には Hyper-V が必要  Hyper-V が必要な場合は、サポートするハードウェアが必要
  • 12.
    Windows Containers の基本要素 Container Host  Windows Containers の機能が有効化された、物理マシン又は VM  Container Host 上で 1 つ以上の Container を実行する  Container Image  ソフトウェア(の一部)を単体で実行可能な形でパッケージングしたもの  一般的には、軽量  実行に必要となるコード、ランタイム、ライブラリ、設定、ツール等を含む  Container OS Image  OS 環境を提供する Container Image  全ての Container Image は、Container OS Image を 1st partition として構築される  Microsoft により提供され、変更不可  Container Repository  Container Image を管理するリポジトリ  Docker Hub や Azure Container Registry 等
  • 13.
    2 種類の ContainerOS Image  microsoft/windowsservercore  Windows Server Core ベースのイメージ  イメージサイズは大きい  Nano Server をサポートしないアプリケーションや Windows 機能を利用したい場合に使用  microsoft/nanoserver  Nano Server ベースのイメージ  イメージサイズは比較的小さい  IIS + .NET Core のモダン Web アプリケーションなど、新しいアプリケーション・Containers 環境を意識して設計されたアプリケーションで使用
  • 14.
  • 15.
    2種類の Containers Windows Servercontainers: shared kernel Hyper-V isolation: isolated kernel Hardware Container Container Container Hyper-V Container Kernel Container Kernel Container Kernel
  • 16.
    2種類の Containers  WindowsServer containers  通常の(一般的な)Containers  Container は、ホスト OS の kernel を使用  Hyper-V containers と比べて軽量(オーバーヘッドが少ない)  所謂 Linux の Containers と同じ  Hyper-V containers  Hyper-V の機能を利用してリソース隔離した Containers  Container は、独自の OS kernel を使用  Windows Server containers と比べて、分離レベルが高い(オーバーヘッドは多い)
  • 17.
    どちらを使うか?  今のところは Hyper-Vcontainers を推奨  Windows Server containers の場合、ホストと Container の OS バージョンに注意  https://docs.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/version- compatibility  Nano Server ベースのイメージを使用するには Hyper-V containers が必要となる  Linux ベースのイメージを使用する場合も Hyper-V containers が必要となる  Client containers (Containers on Windows 10) は Hyper-V containers のみサポート docker run -it --isolation process microsoft/windowsservercore powershell C:¥Program Files¥Docker¥Docker¥Resources¥bin¥docker.exe: Error response from daemon: Windows client operating systems only support Hyper-V containers.
  • 18.
    Demo PS> Get-WindowsFeature Hyper-V,Containers| Install-WindowsFeature - IncludeManagementTools PS> Restart-Computer PS> Install-Module -Name DockerProvider -Repository PSGallery -Force PS> Install-Package -Name docker -ProviderName DockerProvider - RequiredVersion 18.03 -Force # Create %programdata%¥docker¥config¥daemon.json PS> Restart-Service docker PS> Invoke-WebRequest -Uri 'https://github.com/linuxkit/lcow/releases/download/4.14.29- 0aea33bc/release.zip' -UseBasicParsing -OutFile .¥Downloads¥release.zip PS> Expand-Archive .¥Downloads¥release.zip -DestinationPath "$Env:ProgramFiles¥Linux Containers¥." Prepare Container Hosts
  • 19.
    Windows Containers を使う Windows Server  DockerMsftProvider or DockerProvider PS Module をインストール  docker パッケージをインストール  再起動  https://docs.microsoft.com/ja-jp/virtualization/windowscontainers/quick- start/quick-start-windows-server  https://docs.microsoft.com/ja-jp/virtualization/windowscontainers/quick- start/using-insider-container-images
  • 20.
    確認ポイント  docker version Client version / Server (docker engine) version  Experimental  docker info  Default Isolation  Kernel Version  Experimental
  • 21.
    Windows 環境向け Dockerclient  (現時点で)Windows 環境向けに特異な docker client option  --isolation  分離モードの指定  --isolation hyperv // クライアント OS のデフォルト  --isolation process // サーバー OS のデフォルト  --platform  (Windows Host 上で)どの OS kernel を使用するかの指定  --platform=linux // LCOW を使用  --platform=windows // Windows を使用
  • 22.
    Linux containers onWindows hosts  Windows Host で Linux ベースの Container Image を実行可能  Windows Server 2016 では利用不可  Windows Server 1709 以降(ホスト)  Docker Engine 17.11 以降  LinuxKit / LCOW (最新の Release を推奨)
  • 23.
    Windows Containers の今後 Container OS Image としての進化  イメージサイズをより小さく  Container Host としての進化  オーケストレーションに注力  Docker engine / Kubernetes との連携
  • 24.
    まとめ  Windows Containers OS virtualization  Hyper-V isolation  Containers の使い始め方  PowerShell 数行で構成可能  Containers 使ってみてください!
  • 25.
    やること  Windows Serverで Container を使うために必要なこと  Get-WindowsFeature Hyper-V,Containers | Install-WindowsFeature - IncludeManagementTools  Restart-Computer  Install-Module -Name DockerProvider -Repository PSGallery -Force  Install-Package -Name docker -ProviderName DockerProvider -RequiredVersion 18.03 -Force
  • 26.
    やること(オプション)  Windows Serverで Linux Container Image を使うために必要なこと  Docker Engine の Experimental Support を有効化  %programdata%¥docker¥config¥daemon.json  Restart-Service docker  Invoke-WebRequest -Uri 'https://github.com/linuxkit/lcow/releases/download/4.14.29- 0aea33bc/release.zip' -UseBasicParsing -OutFile .¥release.zip  Expand-Archive .¥release.zip -DestinationPath "$Env:ProgramFiles¥Linux Containers¥."
  • 27.
    参考資料  Containers 101with Microsoft and Docker  https://channel9.msdn.com/Blogs/containers/Containers-101-with-Microsoft- and-Docker?ocid=player  Install Docker Enterprise Edition for Windows Server  https://docs.docker.com/install/windows/docker-ee/