はじめに
先日リリースされたVMware Fusion 11.5.5から、コンテナが公式にサポートされるようになりました。Dockerにおけるdocker
コマンドのように、vctl
と呼ばれるコマンドを通して、コンテナイメージのpullやbuild、コンテナの起動などを行うことができます。
この機能はもともとProject Nautilusという名前で開発され、Tech Previewバージョンが公開されていました。vSphereとKubernetesを統合するProject Pacificの技術を利用して、デスクトップ環境でも仮想マシンとコンテナをシングルプラットフォームで扱えることを目標としています。
使い方
準備
VMware Fusion 11.5.5は、MyVMwareもしくは以下のリンクからダウンロードすることが可能です。
VMware Fusionのインストールが完了したら、vctl system start
コマンドを実行して、コンテナのためのストレージやネットワークの準備を行います。
$ vctl system start
Preparing storage...
Container storage has been prepared successfully under /Users/tomoyuki/.vctl/storage
Preparing container network, you may be prompted to input password for administrative operations...
Password:
Container network has been prepared successfully using vmnet: vmnet10
Launching container runtime...
Container runtime has been started.
次にvctl
コマンドでコンテナが動かせるかどうか確認するために、hello-world
イメージをプルした後、起動してみます。
$ vctl pull hello-world
INFO Pulling from index.docker.io/library/hello-world:latest
─── ────── ────────
REF STATUS PROGRESS
─── ────── ────────
index-sha256:6a65f928fb91fcfbc963f7aa6d57c8eeb426ad9a20c7ee045538ef34847f44f1 Done 100% (2101/2101)
manifest-sha256:90659bf80b44ce6be8234e6ff90a1ac34acbeb826903b02cfa0da11c82cbc042 Done 100% (525/525)
layer-sha256:0e03bdcc26d7a9a57ef3b6f1bf1a210cff6239bff7c8cac72435984032851689 Done 100% (2529/2529)
config-sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b Done 100% (1510/1510)
INFO Unpacking hello-world:latest...
INFO done
$ vctl run hello-world
INFO container hello-world-6d16 started
Hello from Docker!
This message shows that your installation appears to be working correctly.
~~ 省略 ~~
イメージのビルド・起動・プッシュ
次に、nginx
イメージをベースにindex.html
を置き換えた新しいイメージをvctl build
コマンドでビルドしてみます。
$ cat Dockerfile
FROM nginx
COPY ./index.html /usr/share/nginx/html
$ cat index.html
Hello Fusion!!
$ vctl build -t test-nginx:latest ./
INFO building image test-nginx:latest with jobId 5659ded6-b05f-4a86-9ffc-a0a9b466fd9e using internal builder instance...
INFO preparing base images...
INFO looking for base image: nginx from local storage
INFO resolved image nginx to digest sha256:d9002da0297bcd0909b394c26bd0fc9d8c466caf2b7396f58948cac5318d0d0b as cache key
INFO cannot find image nginx from local storage, pulling from remote registry
INFO pulling image: index.docker.io/library/nginx:latest
INFO Pulling from index.docker.io/library/nginx:latest
~~ 省略 ~~
INFO creating image test-nginx:latest
INFO successfully built image test-nginx:latest
このtest-nginx
イメージを起動して、curl
コマンドでindex.html
ファイルに取得してみます。起動したコンテナのIPアドレスは、vctl ps
コマンドで確認できます。
$ vctl run -n test-nginx1 -t -d test-nginx
INFO container test-nginx1 started and detached from current session
$ vctl ps
──── ───── ─────── ── ───── ────── ─────────────
NAME IMAGE COMMAND IP PORTS STATUS CREATION TIME
──── ───── ─────── ── ───── ────── ─────────────
test-nginx1 test-nginx:latest /docker-entrypoint.s... 172.16.34.131 n/a running 2020-06-08T00:46:29+09:00
$ curl 172.16.34.131
Hello Fusion!!
このイメージをプライベートリポジトリであるharbor.tta.lab
にプッシュしてみます。
$ vctl tag test-nginx:latest harbor.tta.lab/library/test-nginx:latest
$ cat passwd.txt | vctl push -u admin --password-stdin --skip-ssl-check harbor.tta.lab/library/test-nginx:latest
INFO pushing image: harbor.tta.lab/library/test-nginx:latest to harbor.tta.lab/library/test-nginx:latest
─── ────── ────────
REF STATUS PROGRESS
─── ────── ────────
manifest-sha256:275d7220cedb3665c93df269116e06c11f78036e2e707789de1ffa61b1a7de3a Done 100% (1234/1234)
layer-sha256:b5ef027ab62986b6152ae013825b744131610b3da275879971e61ebcfa5d4469 Done 100% (235/235)
layer-sha256:a2c431ac2669038db7a758a597c7d1d53cdfb2dd9bf6de2ad3418973569b3fc7 Done 100% (900/900)
layer-sha256:8de28bdda69b66a8e07b14f03a9762f508bc4caac35cef9543bad53503ce5f53 Done 100% (538/538)
config-sha256:0419812b676628e0f600536301336d4c044372de9225239bdf2ae5798fdc185e Done 100% (7786/7786)
layer-sha256:afb6ec6fdc1c3ba04f7a56db32c5ff5ff38962dc4cd0ffdef5beaa0ce2eb77e2 Done 100% (27098756/27098756)
layer-sha256:dd3ac8106a0bbe43a6e55d2b719fc00a2f8f694e90c7903403e8fdecd2ccc57f Done 100% (26210578/26210578)
layer-sha256:e070d03fd1b5a05aafc7c16830d80b4ed622d546061fabac8163d3082098a849 Done 100% (669/669)
※passwd.txt
にパスワードが記載されています。
プライベートリポジトリのGUIから正常にプッシュされていることが確認できます。

コンテナをホストするVM
コンテナはPhoton OSをベースとする軽量なVM上で動いています。
vctl describe
コマンドを実行することで、コンテナが稼働しているVMの.vmx
ファイルのパスが確認できます。デフォルトで、2 vCPU・メモリ 1GBで構成されています。
$ vctl describe test-nginx1
Name: test-nginx1
Status: running
Command: /docker-entrypoint.sh nginx -g daemon off;
Container rootfs in host: /Users/tomoyuki/.vctl/storage/containerd/state/io.containerd.runtime.v2.task/vctl/test-nginx1/rootfs
IP address: 172.16.34.131
Creation time: 2020-06-08T00:46:29+09:00
Image name: test-nginx:latest
Image size: 50.9 MiB
Host virtual machine: /Users/tomoyuki/.vctl/.r/vms/test-nginx1/test-nginx1.vmx
Container rootfs in VM: /.containers/test-nginx1
Access in host VM: vctl execvm --sh -c test-nginx1
Exec in host VM: vctl execvm -c test-nginx1 /bin/ls
また、コンテナのrootfsはMac上にコンテナ名でマウントされるため、Finderから直接コンテナ内のファイルにアクセスすることが可能です。
