LoginSignup
68
71

More than 3 years have passed since last update.

Windows10 HomeでDocker環境を導入する

Last updated at Posted at 2020-02-22

はじめに

昨今さまざまな環境構築・サービス利用でDockerが使われているので
自分も家のWin10 PCで試してみるべきだと考え実行に移した次第です。その際の備忘録です。

対象

  • Windows 10 HomeでDockerを使おうとしている方
  • Windows 10 Pro でDockerを使おうとしているけれどVMwareやVirtualBoxも使いたいのでHyper-V有効にできない方
  • ちょっと前の自分

環境

  • Windows 10 Home 64bit
  • CPU: Core i7-8700 @ 3.20GHz
  • RAM: 16GB

前段

Windows 10 Proの方は「Docker Desktop for Windows」を使っている方が多いかと思います。
Win10 ProでサポートされるHyper-Vというハイパーバイザ上でLinuxマシンおよびDockerエンジンを動かす構成です。
しかしHyper-Vを有効にすると、VMwareやVirtual Boxといった仮想化ソフトが使えなくなることがあります。

※CPUによって使える場合もあるようです?興味深い考察がされているようです:
 VirtualBox 6.0 から Hyper-V と共存できるはず

そんな感じでHyper-Vが使いづらい方はVirtual Box上でDockerマシンを動かす「Docker Toolbox」で何とかすることになりそうです。
Hyber-V上で動かすMobyLinuxVMと、Virtual Box上で動かすdocker-machineとで実際どこまで機能やパフォーマンスが違うのかはよくわかっていませんが…

ただいずれにせよ、自分の場合はそもそもWin10 HomeなのでDocker Toolbox一択です。

書いた内容

  • Docker Toolbox入手とインストール、Hello-World実行までの手順
  • 途中でつまずいた点と対策の紹介

インストールの流れ

  1. CPU仮想化確認
    タスクマネージャ→パフォーマンス→CPU にて仮想化: 有効となっていればOKです。
    1.jpg
    有効になっていない場合はBIOSの設定などで有効にしてやる必要があります。(このあたりの手順は割愛で…)

  2. Docker Toolbox入手
    https://docs.docker.com/toolbox/toolbox_install_windows/
    2a.jpg
    手順の途中で最新版の入手先リンクがあります。GitHubから取ってくるのですね。
    https://github.com/docker/toolbox/releases
    2b.jpg

  3. インストール
    画面に従って進めます。
    Virtual BoxやGit for Windowsも一緒に入れるか聞かれるので、まだ入れていないものはチェックして先に。
    3.jpg

    Virtual Boxを入れる場合はInstall VirtualBox with NDIS5 driver [default NDIS6] というチェックボックスが出てきますが、初期状態ではチェックが入っていません。
    チェックを入れるべきか入れないべきか、ネット上の記事では意見がいろいろありますが自分はとりあえずチェック無しで進みました。後で何か失敗したらこの部分に起因するかどうか確認します。

  4. 起動
    デスクトップにDocker Quickstart Terminalのショートカットができたら、そこから起動します。
    起動すると最新のboot2docker.isoをGitHubから取得し

    • defaultという名前のdocker-machineを作成
    • Virtual Boxのホストオンリーネットワークアダプタを1つ新規作成

    を実施した上で、作成したdocker-machine(default)が無事起動されました。

    Creating CA: C:\Users\<user>\.docker\machine\certs\ca.pem
    Creating client certificate: C:\Users\<user>\.docker\machine\certs\cert.pem
    Running pre-create checks...
    (default) Image cache directory does not exist, creating it at C:\Users\<user>\.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\xxx\.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...
     (略)
    Docker is up and running!
    To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env default
    

    5.jpg

ここまででつまづいたポイントと対応

ここまでで色々とはまったことがあるので記録しておきます。(ある意味本記事のメイン)

ショートカットから起動できない
Docker Quickstart Terminal のショートカットでは
C:\Program Files\Git\bin\bash.exe
を起動しようとしますが、Git for WindowsがDドライブなどにインストールされていた場合はbashが見つからず怒られます。
→ショートカットを編集して然るべき場所を指定してあげます。

Docker Machine is not installed. Please re-run the Toolbox installer and try again. というエラーが出てしまう
→Docker Toolboxのインストール先のパス(DOCKER_TOOLBOX_INSTALL_PATH)が環境変数に無い可能性があります。
 会社内PCなどで、Admin権限ユーザーでDocker Toolboxをインストール→一般ユーザーが起動 とした場合などです。
→上記環境変数をシステム環境変数に追加してあげます。
 (例) DOCKER_TOOLBOX_INSTALL_PATH : C:\Program Files\Docker Toolbox

プロキシ環境下でboot2docker.isoが取得できずにエラーになってしまう
→プロキシの環境変数を設定してあげます。
 (例)
  HTTP_PROXY : http\://172.16.1.1:8080
  HTTPS_PROXY : http\://172.16.1.1:8080 ※httpsだとエラー(参考: https://github.com/docker/machine/issues/3210)

boot2docker.isoを取得したもののdocker-machine生成に失敗してしまう
C:\Users<ユーザー>.docker\machine\cache に置かれたイメージが本来50MB程度のはずが5KB程度しかない(破損?)
→なぜ破損したかは不明ですが、取得すべきイメージを手動で取ってくれば問題ありません。
 https://github.com/boot2docker/boot2docker/releases/download/v19.03.5/boot2docker.iso
 取得したイメージを
 C:\Users\<ユーザー>\.docker\machine\cache
 C:\Users\<ユーザー>\.docker\machine\machines\default
 に置いて(cacheには置く必要ないかもしれません)、再度Docker QuickStart Terminal実行してあげます。

docker-machine defaultは生成されたがこんなエラーが出る

 This machine has been allocated an IP address, but Docker Machine could not reach it successfully. 
 SSH for the machine should still work, but connecting to exposed ports, such as the Docker daemon port (usually <ip>:2376), may not work properly.
 (以下略)

→調査中…VPN使用していたのでその影響かもしれません?
 ただしTera TermからのSSH接続(docker:tcuser)などで問題なく使用できました。

Hello-World

$ docker run --rm hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:fc6a51919cfeb2e6763f62b6d9e8815acbf7cd2e476ea353743570610737b752
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/

問題なく使用できています。

$ docker-machine ssh default
   ( '>')
  /) TC (\   Core is distributed with ABSOLUTELY NO WARRANTY.
 (/-_--_-\)           www.tinycorelinux.net

SSH接続も大丈夫です。

今回はここまでで終了です。

68
71
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
68
71