Home > Windows にまつわる e.t.c.

コンテナ環境セットアップとコンテナ起動/停止


WS16TP3 から「コンテナ」テクノロジーがサポートされました。

コンテナは、仮想化テクノロジーの1つで、アプリケーションの動作環境を仮想化します。

Hyper-V が OS を仮想化するのに対して、OS の中で稼働するアプリケーション動作環境を仮想化します。

 

 

このテクノロジーは App-V と同じで、MS Office 2013 や Office 365 と同様動作です。

 

WS16T3 のコンテナ操作 Step by Step は以下にあります。

Windows Containers
https://msdn.microsoft.com/en-us/virtualization/windowscontainers/containers_welcome

 

WS16TP3 には Containers の Feature があるのですが、こいつを有効にするだけだとうまく操作できないので(はい、僕が不勉強なのです)、Step by Step に従って、まずは基本的な環境構築とコンテナの開始/停止をしてみましょう。

 

 

コンテナ環境の構築

WS16TP3のコンテナ環境は、VM でも、物理マシンでも動作しますので、どちらか準備できる環境に WS16TP3 をインストールします。

僕は WS16TP3 Hyper-V の VM で検証していますが、WS12R2 や Windows 8.1u1/Windows 10 Hyper-V VM でも大丈夫だと思います。

慣れれば GUI 無しでもよいでしょうが、最初は GUI アリの方が操作しやすいでしょう。

まずは、構築用のスクリプトダウンロードと、スクリプト実行します。

PS C:\> wget -uri https://aka.ms/setupcontainers -OutFile C:\ContainerSetup.ps1
PS C:\> C:\ContainerSetup.ps1

 

すると再起動され、環境構築と必要なモジュールをダウンロードします。

Querying status of Windows feature: Containers...
Feature Containers is already enabled.
Enabling container networking...
Creating container switch (NAT)...
Creating NAT for 172.16.0.0/12...
Installing Container OS image from https://aka.ms/ContainerOSImage (this may take a few minutes)...
Downloading Container OS image (WIM) from https://aka.ms/ContainerOSImage to C:\Windows\system32\ContainerBaseImage.wim...

この段階で当分(1hくらいかそれ以上)待たされるので、フリーズしたのかと慌てて再起動と課せずに辛抱強く待ってください。

 

準備が終わると以下のようにプロンプトが出てきます。

Querying status of Windows feature: Containers...
Feature Containers is already enabled.
Enabling container networking...
Creating container switch (NAT)...
Creating NAT for 172.16.0.0/12...
Installing Container OS image from https://aka.ms/ContainerOSImage (this may take a few minutes)...
Downloading Container OS image (WIM) from https://aka.ms/ContainerOSImage to C:\Windows\system32\ContainerBaseImage.wim...
Waiting for VMMS to return image at (09/06/2015 17:00:32)...
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.10514.0'].Name

Installing Docker...
This script uses a third party tool: NSSM service manager. For more information, see https://nssm.cc/usage
Downloading NSSM...
Extracting NSSM from archive...
Creating Docker program data...
Configuring NSSM for Docker service...
Waiting for Docker daemon...
Successfully connected to Docker Daemon.
Tagging new base image...
Script complete!
PS C:\Windows\system32>

 

ipconfig を見ると 仮想 NIC が構成されたようです。

PS C:\> ipconfig

Windows IP Configuration


Ethernet adapter vEthernet (Virtual Switch):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::c1f:7764:756c:1c2d%7
   IPv4 Address. . . . . . . . . . . : 172.16.0.1
   Subnet Mask . . . . . . . . . . . : 255.240.0.0
   Default Gateway . . . . . . . . . :

Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . : vwnet.jp
   IPv6 Address. . . . . . . . . . . : 2400:400e:400:0:fcff:63c2:689c:e5c3
   IPv6 Address. . . . . . . . . . . : fd75:f582:7ae3:0:fcff:63c2:689c:e5c3
   Link-local IPv6 Address . . . . . : fe80::fcff:63c2:689c:e5c3%3
   IPv4 Address. . . . . . . . . . . : 192.168.33.74
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : fe80::1%3
                                       192.168.33.254

Tunnel adapter isatap.vwnet.jp:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . : vwnet.jp

Tunnel adapter isatap.{B7EFE77B-18A8-4185-824F-88687B4E947A}:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

 

まずは準備されたコンテナイメージを確認します。

PS C:\> Get-ContainerImage

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

 

コンテナ用に仮想スイッチが作られました。
この環境には Hyper-V の役割は入っていませんが、コンテナ用に Hyper-V テクノロジーが使われるようです。

PS C:\> Get-VMSwitch

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

 

コンテナイメージからコンテナを作成します。

PS C:\> $container = New-Container -Name "MyContainer" -ContainerImageName WindowsServerCore -SwitchName "Virtual Switch"
PS C:\> Get-Container

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

 

コンテナ起動前のメモリー状態を確認しておきます。

 

コンテナ起動

PS C:\> Start-Container -Name "MyContainer"
PS C:\> Get-Container

Name State Uptime ParentImageName
---- ----- ------ ---------------
MyContainer Running 00:00:05.5860000 WindowsServerCore

 

コンテナ起動後のメモリー状態を確認します。
VM を起動しているわけではないので、メモリはあまり消費していません。

 

コンテナ に接続して ipconfig してみると、コンテナが仮想 NIC に接続されているのがわかります。
コンテナは OS の一部として動作するしかないのかと思っていたのですが、VM のように、独立してネットワークアクセスできるようです(この辺りはまだ手探り)

PS C:\> Enter-PSSession -ContainerId $container.ContainerId -RunAsAdministrator
[36d3c335-8c2]: PS C:\Windows\system32> ipconfig

Windows IP Configuration


Ethernet adapter vEthernet (Virtual Switch-36D3C335-8C2B-4EFD-B623-7A4CF65C4C34-0):

   Connection-specific DNS Suffix  . : vwnet.jp
   Link-local IPv6 Address . . . . . : fe80::54c0:383f:9c18:5d49%17
   IPv4 Address. . . . . . . . . . . : 172.16.0.2
   Subnet Mask . . . . . . . . . . . : 255.240.0.0
   Default Gateway . . . . . . . . . : 172.16.0.1

[36d3c335-8c2]: PS C:\Windows\system32> exit

 

コンテナ停止

PS C:\> Stop-Container -Name "MyContainer"
PS C:\> Get-Container

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

 

コンテナを停止したので、メモリー状態を見ると、増加したメモリーが回復されています。

 

最後にコンテナを削除します。

PS C:\> Get-Container | Remove-Container -Force

 

コンテナは VM と違うのですが、ネットワークは VM の様にできるようです。
まだまだ手探りですが、これから勉強します。

 

 

back.gif (1980 バイト)

home.gif (1907 バイト)

Copyright © MURA All rights reserved.