Windows 10 Home で docker動作環境を構築

## はじめに

自宅のPCがWindows10でdocker for windowsを使用できないため、代替となるdocker動作環境を構築する手順のメモ

## 環境

|項目|値|
|---|---|
|OS|Windows10 Home|

## サマリ

1. Docker ToolBoxのインストール

## Docker ToolBoxのインストール

1. (dockerの公式ぺージ)[https://docs.docker.com/toolbox/toolbox_install_windows/]にアクセス
2. 手順に従ってCPUの仮想化が有効であることを確認 
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/304089/fff68884-ca18-e630-0dc5-afa7c1e6da71.png)
3. こちらも手順にしたがっdocker Tool Boxの[GitHub](https://github.com/docker/toolbox/releases)からインストーラーをダウンロード
    - 作業時の最新版のv19.03.1のインストーラー``DockerToolbox-19.03.1.exe``ダウンロード
4. インストーラーを実行
- 起動
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/304089/c8107ac5-a86d-10e5-3805-59bfcd845121.png)
- NEXT
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/304089/28ba70c0-8df8-221f-f330-257e794c06a3.png)
- デフォルト
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/304089/c4b316f4-6c43-260e-289d-6e84e21d2c75.png)
- Git for Windows も入れた
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/304089/29719cab-41ef-27f6-9a98-e15d2d038666.png)
- NDIS5をチェック
    - 参考:[Windows10マシンにDocker Toolbox を入れて個人用の開発環境を作る](https://qiita.com/osuo/items/99a2b7413ce75f8217be)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/304089/82275329-948b-5a84-c92f-6cd3a64983b1.png)
1. Install
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/304089/bc74bb44-f8d5-aef2-88f6-c2b44436f30c.png)
1. インストール完了。デスクトップにDocker Quickstart Terminalのショートカットが作成される。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/304089/1dc052a2-b999-c154-1a2b-9a31f0274e29.png)

## Docker Quickstart Terminal

1. デスクトップのショートカットから起動
2. 以下のエラーが発生。VirtualBoxのhost-only-networkの作成に失敗したとのこと。

``` bash
Creating CA: C:\\hoge\.docker\machine\certs\ca.pem
Creating client certificate: C:\Users\hoge\.docker\machine\certs\cert.pem
Running pre-create checks...
(default) Image cache directory does not exist, creating it at C:\Users\hoge\.docker\machine\cache...
(default) No default Boot2Docker ISO found locally, downloading the latest release...
(default) Latest release for github.com/boot2docker/boot2docker is v19.03.5
(default) Downloading C:\Users\hoge\.docker\machine\cache\boot2docker.iso from https://github.com/boot2docker/boot2docker/releases/download/v19.03.5/boot2docker.iso...
(default) 0%....10%....20%....30%....40%....50%....60%....70%....80%....90%....100%
Creating machine...
(default) Copying C:\Users\hoge\.docker\machine\cache\boot2docker.iso to C:\Users\hoge\.docker\machine\machines\default\boot2docker.iso...
(default) Creating VirtualBox VM...
(default) Creating SSH key...
(default) Starting the VM...
(default) Check network to re-create if needed...
(default) Windows might ask for the permission to create a network adapter. Sometimes, such confirmation window is minimized in the taskbar.
(default) Creating a new host-only adapter produced an error: C:\Program Files\Oracle\VirtualBox\VBoxManage.exe hostonlyif create failed:
(default) 0%...
(default) Progress state: E_FAIL
(default) VBoxManage.exe: error: Failed to create the host-only adapter
(default) VBoxManage.exe: error: Querying NetCfgInstanceId failed (0x00000002)
(default) VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component HostNetworkInterfaceWrap, interface IHostNetworkInterface
(default) VBoxManage.exe: error: Context: "enum RTEXITCODE __cdecl handleCreate(struct HandlerArg *)" at line 94 of file VBoxManageHostonly.cpp
(default)
(default) This is a known VirtualBox bug. Let's try to recover anyway...
Error creating machine: Error in driver during machine creation: Error setting up host only network on machine start: The host-only adapter we just created is not visible. This is a well known VirtualBox bug. You might want to uninstall it and reinstall at least version 5.0.12 that is is supposed to fix this issue
Looks like something went wrong in step ´Checking if machine default exists´... Press any key to continue...
```

### host-only-network作成失敗エラーの解消

エラーメッセージによると、``You might want to uninstall it and reinstall at least version 5.0.12 that is is supposed to fix this issue`` とのこと。
VirtualBoxのバージョンを確認。

- この時点でのバージョン：5.2.20
- リリース済みの最新バージョン：6.1.0

指示に従ってアンインストール→インストール。
インストールはデフォルト値で進める。
インストール後、Docker Quickstart Terminalを起動→起動成功。

```
Starting "default"...
(default) Check network to re-create if needed...
(default) Windows might ask for the permission to create a network adapter. Sometimes, such confirmation window is minimized in the taskbar.
(default) Found a new host-only adapter: "VirtualBox Host-Only Ethernet Adapter #2"
(default) Windows might ask for the permission to configure a network adapter. Sometimes, such confirmation window is minimized in the taskbar.
(default) Windows might ask for the permission to configure a dhcp server. Sometimes, such confirmation window is minimized in the taskbar.
(default) Waiting for an IP...
Machine "default" was started.
Waiting for SSH to be available...
Detecting the provisioner...
Started machines may have new IP addresses. You may need to re-run the `docker-machine env` command.
Regenerate TLS machine certs?  Warning: this is irreversible. (y/n): Regenerating TLS certificates
Waiting for SSH to be available...
Detecting the provisioner...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...



                        ##         .
                  ## ## ##        ==
               ## ## ## ## ##    ===
           /"""""""""""""""""\___/ ===
      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ /  ===- ~~~
           \______ o           __/
             \    \         __/
              \____\_______/

docker is configured to use the default machine with IP 192.168.99.100
For help getting started, check out the docs at https://docs.docker.com


Start interactive shell

nakay@DESKTOP-21KMQ3S MINGW64 /c/Program Files/Docker Toolbox
$
```

## hello-worlld
何はともあれ``hello world``。``dockr run``を実行して成功。

```bash
nakay@DESKTOP-21KMQ3S MINGW64 /c/Program Files/Docker Toolbox
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:4fe721ccc2e8dc7362278a29dc660d833570ec2682f4e4194f4ee23e415e1064
Status: Downloaded newer image for hello-world:latest

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.
    (amd64)
 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 an Ubuntu container with:
 $ docker run -it ubuntu bash

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/
```