以前は、vagrant+virtualbox で仮想マシンを作成してましたが、m2 mac に端末を変えたため、multipass に切り替えました。
multipass は、Ubuntu の仮想マシンを簡単に作成できるツールです。multipass を使用することで、仮想マシンの作成、起動、停止、削除などの操作を簡単に行うことができます。
$ brew install multipass
==> Installing Cask multipass
==> Running installer for multipass with sudo; the password may be necessary.
Password:
installer: Package name is multipass
installer: Installing at base path /
installer: The install was successful.
🍺 multipass was successfully installed!
$ multipass version
multipass 1.13.1+mac
multipassd 1.13.1+mac
# 新規作成
$ multipass launch -n test-vm-01
Launched: test-vm-01
# 確認
$ multipass list
Name State IPv4 Image
test-vm-01 Running 192.168.64.2 Ubuntu 22.04 LTS
$ multipass info test-vm-01
Name: test-vm-01
State: Running
Snapshots: 0
IPv4: 192.168.64.2
Release: Ubuntu 22.04.4 LTS
Image hash: 40ea1181447b (Ubuntu 22.04 LTS)
CPU(s): 1
Load: 0.07 0.04 0.01
Disk usage: 1.6GiB out of 4.8GiB
Memory usage: 150.2MiB out of 962.3MiB
Mounts: --
# 停止
$ multipass stop test-vm-01
# 起動
$ multipass start test-vm-01
# 削除 (-p で永続化)
$ multipass delete test-vm-01 -p
# シェルに入る
$ multipass shell test-vm-01
# マウントする
$ multipass mount mnt test-vm-01:~/ubuntu/mnt
# 鍵作成
$ ssh-keygen -t rsa -b 4096 -C "" -f multipass
# cloud-init 作成
$ vim multipass.yml
#!/bin/sh
AUTHORIZED_KEYS=$(cat multipass.pub )
cat > ./multipass_docker.yaml << _EOF_
---
locale: en_US.UTF8
timezone: Asia/Tokyo
package_upgrade: true
users:
- name: ubuntu
sudo: ALL=(ALL) NOPASSWD:ALL
ssh-authorized-keys:
- ${AUTHORIZED_KEYS}
packages:
- docker
- docker-compose
- avahi-daemon
- apt-transport-https
- ca-certificates
- curl
- gnupg
- lsb-release
runcmd:
- sudo curl -fsSL https://get.docker.com | sudo bash
- sudo systemctl enable docker
- sudo systemctl enable -s HUP ssh
- sudo groupadd docker
- sudo usermod -aG docker ubuntu
_EOF_
# 起動
$ multipass launch -n test-vm-01 --cloud-init multipass.yml
# 確認
$ multipass exec test-vm-01 docker version
Client: Docker Engine - Community
Version: 25.0.5
...