Windows Server 2016 Technical Preview 4(TP4)でWindows Server Containers

Windows Server上でDockerと同じようにアプリケーションを「コンテナ」にパッケージングして、デプロイ、実行できるようになったので、試してみる。

利用イメージ

 ------------------------  コンテナ作成  ------------------------
 |WindowsServerCore     |--------------→|コンテナ              |
 | (コンテナイイメージ) |                |(アプリをインストール)|
 ------------------------                ------------------------
                                                   |
                                                   |コンテナイメージ作成
                                                   |
                                          ----------------------------
                                          |アプリ入りコンテナイメージ|
                                          ----------------------------
                                                   |
                                                   |
-----------------------                  ----------------------------
|アプリを追加し       |                   |  リポジトリとして保管    |
|    コンテナを利用   |    コンテナ作成   |                          |
|                     | ←----------------|                          |
-----------------------                   ----------------------------
  リポジトリとあるコンテナイメージから派生していろんなアプリを追加
  したコンテナができる(共通アプリをインストールした時点でイメージ化して
  リポジトリに保管しておく)

Install

Win-Docker1.png

Win-Docker3.png

コンテナイメージやセットアップスクリプトをダウンロード

&color(red){PowerShellを管理者権限で実行}

cd \
PS C:\> wget -uri https://aka.ms/tp4/Install-ContainerHost -OutFile C:\Install-ContainerHost.ps1
PS C:\ .\ContainerSetup.ps1
Querying status of Windows feature: Containers...
Feature Containers is already enabled.
Waiting for Hyper-V Management...
Enabling container networking...
Creating container switch (NAT)...
Creating NAT for 172.16.0.0/12...
Installing ContainerProvider package...
Getting Container OS image (WindowsServerCore) version 10.0.10586.0 from OneGet\
 (this may take a few minutes)...
(1時間以上DLにかかる)

Container base image install complete.  Querying container images...
The following images are present on this machine:
    ContainerImage (Name = 'WindowsServerCore') [Publisher = 'CN=Microsoft', Version = '10.0.10586.0']

Installing Docker...
Creating Docker program data...
This script uses a third party tool: NSSM. For more information, see https://nssm.cc/usage
Downloading NSSM...
Extracting NSSM from archive...
Configuring NSSM for Docker service...
Waiting for Docker daemon...
Successfully connected to Docker Daemon.
Tagging new base image (6801d964fda5)...
Base image is now tagged:
windowsservercore   10.0.10586.0        6801d964fda5        8 weeks ago         0 B
windowsservercore   latest              6801d964fda5        8 weeks ago         0 B
Script complete!

コンテナOSイメージが「C:\ProgramData\Microsoft\Windows\Images」 に入る。

Win-Docker4.png

Docker Daemonのインストールも行われる。

&ref(): File not found: "Win-Docker2png" at page "Windows_Router Memo/Windows2016TP4-Container";

コンテナ関係のコマンド

PS C:\> Get-Command -Module Containers

CommandType     Name                                               Version    S ource
-----------     ----                                               -------    ------
Function        Install-ContainerOSImage                           1.0.0.0    Containers
Function        Uninstall-ContainerOSImage                         1.0.0.0    Containers
Cmdlet          Add-ContainerNetworkAdapter                        1.0.0.0    Containers
Cmdlet          Add-ContainerSharedFolder                          1.0.0.0    Containers
Cmdlet          Connect-ContainerNetworkAdapter                    1.0.0.0    Containers
Cmdlet          Disconnect-ContainerNetworkAdapter                 1.0.0.0    Containers
Cmdlet          Export-ContainerImage                              1.0.0.0    Containers
Cmdlet          Get-Container                                      1.0.0.0    Containers
Cmdlet          Get-ContainerHost                                  1.0.0.0    Containers
Cmdlet          Get-ContainerImage                                 1.0.0.0    Containers
Cmdlet          Get-ContainerMemory                                1.0.0.0    Containers
Cmdlet          Get-ContainerNetworkAdapter                        1.0.0.0    Containers
Cmdlet          Get-ContainerProcessor                             1.0.0.0    Containers
Cmdlet          Get-ContainerSharedFolder                          1.0.0.0    Containers
Cmdlet          Get-ContainerStorage                               1.0.0.0    Containers
Cmdlet          Import-ContainerImage                              1.0.0.0    Containers
Cmdlet          Move-ContainerImageRepository                      1.0.0.0    Containers
Cmdlet          New-Container                                      1.0.0.0    Containers
Cmdlet          New-ContainerImage                                 1.0.0.0    Containers
Cmdlet          Remove-Container                                   1.0.0.0    Containers
Cmdlet          Remove-ContainerImage                              1.0.0.0    Containers
Cmdlet          Remove-ContainerNetworkAdapter                     1.0.0.0    Containers
Cmdlet          Remove-ContainerSharedFolder                       1.0.0.0    Containers
Cmdlet          Set-Container                                      1.0.0.0    Containers
Cmdlet          Set-ContainerMemory                                1.0.0.0    Containers
Cmdlet          Set-ContainerNetworkAdapter                        1.0.0.0    Containers
Cmdlet          Set-ContainerProcessor                             1.0.0.0    Containers
Cmdlet          Set-ContainerSharedFolder                          1.0.0.0    Containers
Cmdlet          Set-ContainerStorage                               1.0.0.0    Containers
Cmdlet          Start-Container                                    1.0.0.0    Containers
Cmdlet          Stop-Container                                     1.0.0.0    Containers
Cmdlet          Test-ContainerImage                                1.0.0.0    Containers

Windowsのコンテナイメージの確認

PS C:\> Get-ContainerImage

Name              Publisher    Version      IsOSImage
----              ---------    -------      ---------
WindowsServerCore CN=Microsoft 10.0.10586.0 True

コンテナ作成

PS C:\> New-Container -Name "IsmContainer" -ContainerImageName “WindowsServerCore” -SwitchName "Virtual Switch"

Name         State Uptime   ParentImageName
----         ----- ------   ---------------
IsmContainer Off   00:00:00 WindowsServerCore

コンテナの確認

PS C:\> Get-Container

Name         State Uptime   ParentImageName
----         ----- ------   ---------------
IsmContainer Off   00:00:00 WindowsServerCore

SWの確認

PS C:\> Get-VMSwitch

Name           SwitchType NetAdapterInterfaceDescription
----           ---------- ------------------------------
Virtual Switch NAT

''コンテナの起動 7

PS C:\> Start-Container -Name IsmContainer
PS C:\> Get-Container

Name         State   Uptime           ParentImageName
----         -----   ------           ---------------
IsmContainer Running 00:00:07.0770000 WindowsServerCore
             ^^^^^^^ Off→ Runnig

起動したコンテナを管理するには、PowerShellをリモートから実行する

コンテナに入る

PS C:\> $Container = Get-Container -Name "IsmContainer"
PS C:\> Enter-PSSession -ContainerId $Container.ContainerId -RunAsAdministrator
[IsmContainer]: PS C:\Windows\system32>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^コンテナ内のshell

[IsmContainer]: PS C:\Windows\system32> ping 192.168.10.245

Pinging 192.168.10.245 with 32 bytes of data:
Reply from 192.168.10.245: bytes=32 time<1ms TTL=63
Reply from 192.168.10.245: bytes=32 time<1ms TTL=63

[IsmContainer]: PS C:\Windows\system32> tracert 192.168.10.245

Tracing route to bhr-4grv.ism21.net [192.168.10.245]
over a maximum of 30 hops:

  1     *        *        *     Request timed out.
  2    <1 ms    <1 ms    <1 ms  bhr-4grv.ism21.net [192.168.10.245]

[IsmContainer]: PS C:\Windows\system32> ping www.google.co.jp

Pinging www.google.co.jp [216.58.221.163] with 32 bytes of data:
Reply from 216.58.221.163: bytes=32 time=19ms TTL=55
Reply from 216.58.221.163: bytes=32 time=18ms TTL=55

コンテナから出る

[IsmContainer]: PS C:\Windows\system32> exit
PS C:\>

コンテナのShutdown

PS C:\> Stop-Container -Name IsmContainer
PS C:\> Get-Container

Name         State Uptime   ParentImageName
----         ----- ------   ---------------
IsmContainer Off   00:00:00 WindowsServerCore
             ^^^

参考

                                                                              .

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS