サイトアイコン MiYABiS note.

docker を Windows で使ってみる:Docker for Windows を PowerShell でインストール

お疲れ様です!Docker for Windows をコマンドだけでインストールしたかったのでやってみました。

準備

Docker for Windows をインストールする前に、OSの設定を下記を参考に「コンテナを有効化」まで設定します。

docker を Windows で使ってみる:Hyper-V とコンテナ環境構築

Windows 版の Docker をインストール

インストール

invoke-webrequest -uri https://download.docker.com/win/stable/Docker%20for%20Windows%20Installer.exe -outfile .\dockerInstaller.exe

もしエラー「Internet Explorer エンジンを使用できないか、Internet Explorer の初回起動構成が完了していないため、応答のコンテンツを解析できません。UseBasicParsing パラメーターを指定して再試行してください。」になったときは、「-UseBasicParsing」オプションを付けて実行します。

invoke-webrequest -uri https://download.docker.com/win/stable/Docker%20for%20Windows%20Installer.exe -UseBasicParsing -outfile .\dockerInstaller.exe
.\dockerInstaller.exe install --quiet
Restart-Computer

OS ビルドが 14393 のとき

Windows Server 2016 のトライアル版など OS ビルドが 14393 のときは最新の Docker Desktop for Windows は使えません。
そのときは下記のコマンドを実行します。

invoke-webrequest -uri https://download.docker.com/win/stable/31259/Docker%20for%20Windows%20Installer.exe -outfile .\dockerInstaller.exe

動作確認

[hostname]: PS C:\Users\Hoge\Documents> docker version
Client: Docker Engine - Community
 Version:           18.09.2
 API version:       1.39
 Go version:        go1.10.8
 Git commit:        6247962
 Built:             Sun Feb 10 04:12:31 2019
 OS/Arch:           windows/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.2
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.6
  Git commit:       6247962
  Built:            Sun Feb 10 04:13:06 2019
  OS/Arch:          linux/amd64
  Experimental:     false

エラーになる場合

[hostname]: PS C:\Users\Hoge\Documents> docker version
Client: Docker Engine - Community
 Version:           18.09.2
 API version:       1.39
 Go version:        go1.10.8
 Git commit:        6247962
 Built:             Sun Feb 10 04:12:31 2019
 OS/Arch:           windows/amd64
 Experimental:      false
docker : error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.39/version: open //./pipe/docker_engine: The system cannot find the file specified. In
 the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not runnin
g.
    + CategoryInfo          : NotSpecified: (error during co...is not running.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

この場合は、デフォルトの LinuxEngine の起動に失敗しています。下記コマンドを実行するとエラーメッセージが表示されると思うので対処します。私の環境ではメモリが2GB必要になるので空きがないとエラーになっていました。

& $Env:ProgramFiles\Docker\Docker\DockerCli.exe -SwitchLinuxEngine

エンジン切り替え

& $Env:ProgramFiles\Docker\Docker\DockerCli.exe -SwitchWindowsEngine
[hostname]: PS C:\Users\Hoge\Documents> docker version
Client: Docker Engine - Community
 Version:           18.09.2
 API version:       1.39
 Go version:        go1.10.8
 Git commit:        6247962
 Built:             Sun Feb 10 04:12:31 2019
 OS/Arch:           windows/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.2
  API version:      1.39 (minimum version 1.24)
  Go version:       go1.10.6
  Git commit:       6247962
  Built:            Sun Feb 10 04:28:48 2019
  OS/Arch:          windows/amd64
  Experimental:     false

VM で複数サーバー設定とかするときは GUI よりコマンドの方が楽だったりしますね。