LoginSignup
0
2

More than 1 year has passed since last update.

Multipass と cloud-init で Docker Desktop の代用

Posted at

はじめに

Docker Desktop の有償化がアナウンスされ、猶予期間満了日の 1月 31日も少しずつ近づいてきました。

そんな中で、Multipass と cloud-init を使用して Docker Desktop の代わりにしている記事が Canonical 社のブログにあったので試した記事となります。

実行環境

次の環境で実施しています。

ツール バージョン
OS MacOS Monterey 12.1
Multipass 1.8.1+mac
multipassd 1.8.1+mac

ざっくり使うものの概要

Multipass

コマンド1つで Ubuntu の仮想マシンを構築・管理できるツール

cloud-init

あらかじめ定義を用意しておくことで、仮想マシンの初期設定を自動で実行できるツール

手順

  1. Multipass をあらかじめインストールしておきます
  2. multipass launch コマンドでインスタンスを構築します。この時、--cloud-init - オプションで後続の設定をします

    $ multipass launch --cloud-init - --disk 40G --mem 4G --cpus 4 --name docker-vm <<EOF
    groups:
    - docker
    snap:
      commands:
       - [install, docker]
    runcmd:
    - adduser ubuntu docker
    EOF
    
  3. multipass alias コマンドで docker の仮想マシンへのエイリアスを作成します。自分の場合は後者を実施しました

    cliがインストールされていない場合
    $ multipass alias docker-vm:docker
    
    cliがインストールされている場合
    $ multipass alias docker-vm:docker mpdocker
    
    実行後に表示されるガイド
    You'll need to add this to your shell configuration (.bashrc, .zshrc or so) for
    aliases to work without prefixing with `multipass`:
    
    PATH="$PATH:<ユーザーのホームディレクトリ>/Library/Application Support/multipass/bin"
    

    docker cli が PC にインストールされている場合は、cli の競合が発生してしまうようなので、エイリアス名として名前を変更したものを明示的に設定します。

  4. 実行後に表示されるガイドに記載のパスを .bashrc に設定します

    .bashrc
    export PATH="$PATH:<ユーザーのホームディレクトリ>/Library/Application Support/multipass/bin"
    
  5. .bashrc を再読み込みします

確認

コマンドを実行したら次の結果が表示されました。

$ mpdocker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f
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/

感想

難しい設定も特になく、簡単に実施できたので、選択肢としてよさそうな感じです。

手順の中でインラインで記載している設定は、ファイルとして保存し、それを指定する形でもいけると思います。

参考

0
2
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
0
2