Windows Server2016にDocker for Windowsをインストール
Windows Serverでdockerを使うために、docker for windowsをWindows Server2016上にインストールしてみます。
Docker for Windowsとは?
私程度の知識では、DockerはLinuxのコンテナ技術を使っている仮想技術のひとつという程度ですが、VirtualBoxやVmware playerなどの仮想技術(ホスト型)では、仮想マシンがホストOS上で仮想化ソフトウェアを動かして、仮想化ソフトウェア上でゲストOSを動作させます。ホストOS上で異なる(同じでもいいですが)OSが動作している状態になります。専用の仮想化OSのハイパーバイザだと少し異なりますが、ゲストOSが存在するという点は同じだと思います。
Dockerのようなコンテナ技術は、ゲストOSが存在せず、ホストOSのカーネルを利用して、プロセスやユーザなどを隔離することで、別のOSが動いているかのように動作させることができます。そのため、オーバーヘッドも少なく、軽量で高速に起動、停止などが可能と言われています。
逆にデメリットとして、ゲストOSが存在しないので、異なるシステム(WindwosとLinuxのような)のコンテナは動作させることができない。ということになります。
Windows Server2016では、Windows ServerコンテナとHyper-Vコンテナ機能を有効にすることで、Dockerを利用することもできますが、これは Docker for Windows とは異なるようです。
Docker for Windows
DockerをWindows Server 2016にインストールする Docker for Windows には、いくつかエディションが存在するようですが、ざっくりコミュニティ版とエンタープライズ版があり、且つ、コミュニティ版には、Stable(安定版)とedge(毎月更新されるよう)があるようです。
対応プラットフォーム
http://docs.docker.jp/engine/installation/index.html
導入ガイド
http://docs.docker.jp/docker-for-windows/overview.html
Windows Server上に Docker for Windows をインストールする場合は、エンタープライズ版になる
http://docs.docker.jp/docker-for-windows/step_one.html
Docker for Windowsをインストール
Docker for Windowsのインストール
- Powershellを管理者モードで開きます
- Install-Moduleコマンドを実行します
- Install-Packageコマンドを実行します
- サーバを再起動します
- サーバが起動したらPowershellを管理者モードで開きます
- dockerサービスを起動します
- dockerの情報を確認してみます
Install-Module DockerMsftProvider -Force
Install-Package Docker -ProviderName DockerMsftProvider -Force
実行例
PS C:\Users\Administrator> Install-Module DockerMsftProvider -Force
Install-Package Docker -ProviderName DockerMsftProvider -Force
実行例
PS C:\Users\Administrator> Install-Package Docker -ProviderName DockerMsftProvider -Force Name Version Source Summary ---- ------- ------ ------- Docker 18.09.0 DockerDefault Contains Docker EE for use with Windows Server.
Restart-Computer
Start-Service docker
実行例
PS C:\Users\Administrator> Get-Service docker Status Name DisplayName ------ ---- ----------- Stopped Docker docker PS C:\Users\Administrator> Start-Service docker PS C:\Users\Administrator> Get-Service docker Status Name DisplayName ------ ---- ----------- Running Docker docker
docker version
実行例
PS C:\Users\Administrator> docker version Client: Version: 18.09.0 API version: 1.39 Go version: go1.10.3 Git commit: 33a45cd0a2 Built: unknown-buildtime OS/Arch: windows/amd64 Experimental: false Server: Engine: Version: 18.09.0 API version: 1.39 (minimum version 1.24) Go version: go1.10.3 Git commit: 33a45cd0a2 Built: 11/07/2018 00:24:12 OS/Arch: windows/amd64 PS C:\Users\Administrator> docker info Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 0 Server Version: 18.09.0 Storage Driver: windowsfilter Windows: Logging Driver: json-file Plugins: Volume: local Network: ics l2bridge l2tunnel nat null overlay transparent Log: awslogs etwlogs fluentd gelf json-file local logentries splunk syslog Swarm: inactive Default Isolation: process Kernel Version: 10.0 14393 (14393.2608.amd64fre.rs1_release.181024-1742) Operating System: Windows Server 2016 Standard Version 1607 (OS Build 14393.2608) OSType: windows Architecture: x86_64 CPUs: 4 Total Memory: 7.67GiB Name: WIN-SV16-100 ID: MA5N:U4LX:P63X:ZHQA:GZWN:FZDV:23GA:WHE4:OGG5:K4DT:GN37:C5ME Docker Root Dir: C:\ProgramData\docker Debug Mode (client): false Debug Mode (server): false Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries: 127.0.0.0/8 Live Restore Enabled: false
とりあえずインストールは出来たようです。
コンテナを持ってきてみます
docker自体のインストールができたようなので、コンテナを入手してみます。
- docker pullコマンドを実行します
ここではhello-worldコンテナを入手してみます - 入手したimageを確認してみます
- hello-worldを実行してみます
- 試しにdocker run -it microsoft/windowsservercore powershellを実行してみます
docker pull hello-world
実行例
PS C:\Users\Administrator> docker pull hello-world Using default tag: latest latest: Pulling from library/hello-world bce2fbc256ea: Pull complete 4a14bdf6da80: Pull complete 842bcbb9bd6e: Pull complete 3c15d2487d42: Pull complete Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788 Status: Downloaded newer image for hello-world:latest
docker images
実行例
PS C:\Users\Administrator> docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest 476f8d625669 2 months ago 1.14GB
docker run hello-world
実行例
PS C:\Users\Administrator> docker run hello-world Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (windows-amd64, nanoserver-sac2016) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run a Windows Server container with: PS C:\> docker run -it microsoft/windowsservercore powershell Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/
docker run -it microsoft/windowsservercore powershell
途中でミスったので入手後に確認してみました。
PS C:\Users\Administrator> docker images REPOSITORY TAG IMAGE ID CREATED SIZE microsoft/windowsservercore latest 64d9bc839037 2 weeks ago 11GB hello-world latest 476f8d625669 2 months ago 1.14GB PS C:\Users\Administrator>
とりあえず動いているようです。