dockerの実行環境にVMWare Workstation上のVMを使う
AMD CPUを搭載したノートPCで以下のようなジレンマに遭遇したので、取り組んだ内容をメモ
- WSL2やDocker Desktopを使う場合、「仮想マシンプラットフォーム」や「Hyper-V」が必要
- VMWare Workstationは15.5.5からHyper-V環境下でも共存して動作するようになった
- 共存環境においてVMWare Workstationの仮想マシンはIntel VT-xやAMD-Vを有効化できない
- AMD CPU環境ではHyper-VでAMD-Vを有効化できる仮想マシンはWindowsOSのみ
AMD CPUのWinPCでESXiやコンテナの検証がしたい人には辛い状況です。
(そんなことしたい人がが世界にどの程度いるかはさておき...)
Dockerはリモートに対してコマンドを実行させることも可能なため、
VMWare Workstation上でDocker実行可能な仮想環境を作れば、
Windows環境からDockerコマンドを実行することが可能です。
ただ、結局はLinux仮想マシンでコマンド叩いたほうが幸せになれそう。。。
環境
- Windows 10 Pro 20H2
- VMWare Workstation 16 Pro 16.1.1
- Ubuntu 20.0.4.2
- docker 20.10.6
- docker-compose v0.16.2
仮想マシン側の設定
dockerが動作し、外部からの接続を受け付けられる状況になればOKです。
docker.serviceを書き換えてTCP2375番ポートでListenするように設定を行っています。
$ sudo apt install docker docker.io $ sudo usermod -aG docker `whoami` $ sudo vi /usr/lib/systemd/system/docker.service #ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H fd:// --containerd=/run/containerd/containerd.sock $ sudo systemctl restart docker $ ss -lnt State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 4096 127.0.0.1:37967 0.0.0.0:* LISTEN 0 4096 127.0.0.53%lo:53 0.0.0.0:* LISTEN 0 128 [::]:22 [::]:* LISTEN 0 4096 *:2375 *:*
Windows側の設定
- dockerとdocker-composeのWindowsバイナリをダウンロード。
- docker-compose-Windows-x86_64.exeは解凍したdockerのフォルダに格納。
- 環境変数を編集し、「PATH」に解凍したdockerのフォルダを追加(例:C:\Programs\docker)
- 環境変数を編集し、「DOCKER_HOST」に接続先を指定(例:tcp://192.168.80.10:2375)
以下のように実行できればOK
PS C:\> docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES PS C:\> docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world b8dfde127a29: Pull complete Digest: sha256:f2266cbfc127c960fd30e76b7c792dc23b588c0db76233517e1891a4e357d519 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/ PS C:\>