Colimaにはプロファイル( profile
)という概念があり、--profile
によってVM環境を切り替えることができます。
また --arch
オプションでVMのイメージを切り替えることも可能です。
上記を利用してaarch64とx86_64のDocker環境を両方準備してみます。
方針
ARM Macなので基本的には aarch64(ARM)をデフォルトにします
profile |
ISA |
default |
aarch64 |
x64 |
x86_64 |
各環境を作成
まずaarch64の環境を作成します。
$ colima start --cpu 8 --memory 8 --disk 128 --mount '~/src/:w' --mount '~/tmp:w' --dns 8.8.8.8
次にx86_64の環境を x64
というプロファイル名をつけて作成します。
$ colima start --profile x64 --arch x86_64 --cpu 8 --memory 8 --disk 128 --mount '~/src/:w' --mount '~/tmp:w' --dns 8.8.8.8
この時点で以下のようになっています
$ colima list
PROFILE STATUS ARCH CPUS MEMORY DISK
default Running aarch64 8 8GiB 128GiB
x64 Running x86_64 8 8GiB 128GiB
ColimaはLimaのラッパーなので limactl でも確認してみます。
$ limactl list
NAME STATUS SSH ARCH CPUS MEMORY DISK DIR
colima Running 127.0.0.1:52650 aarch64 8 8GiB 128GiB /Users/k1low/.lima/colima
colima-x64 Running 127.0.0.1:58188 x86_64 8 8GiB 128GiB /Users/k1low/.lima/colima-x64
docker context list
をみるとホストのdockerがどのDockerのエンドポイントを向いているのかがわかります。
$ docker context list
NAME DESCRIPTION DOCKER ENDPOINT KUBERNETES ENDPOINT ORCHESTRATOR
colima colima unix:///Users/k1low/.colima/docker.sock
colima-x64 * colima [profile=x64] unix:///Users/k1low/.colima-x64/docker.sock
default Current DOCKER_HOST based configuration unix:///var/run/docker.sock swarm
desktop-linux unix:///Users/k1low/.docker/run/docker.sock
colima-x64
に *
がついているので、今は x86_64 環境を向いています。
contextの切り替えは docker context use [NAME]
で切り替え可能です。
これで、Colima on ARM Macでaarch64とx86_64のDocker環境を切り替えて使えるようになりました。
--profile=x64
の環境ではx86_64のDockerイメージしかない mysql:5.7
なども動きます。
せっかくなのでベンチマークも取ってみます。
aarch64 環境
$ docker context use colima
colima
Current context is now "colima"
$ docker container run -it --rm --name debian-bullseye debian:bullseye /bin/bash
Unable to find image 'debian:bullseye' locally
bullseye: Pulling from library/debian
c7869242ae9a: Pull complete
Digest: sha256:10b622c6cf6daa0a295be74c0e412ed20e10f91ae4c6f3ce6ff0c9c04f77cbf6
Status: Downloaded newer image for debian:bullseye
root@faabf0fd5dcf:/# apt -y update && apt -y install sysbench
[...]
root@faabf0fd5dcf:/# uname -a
Linux faabf0fd5dcf 5.10.93-0-virt #1-Alpine SMP Thu, 27 Jan 2022 09:34:38 +0000 aarch64 GNU/Linux
root@faabf0fd5dcf:/# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
root@faabf0fd5dcf:/# sysbench cpu --cpu-max-prime=10000 --threads=8 --time=30 run
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
Running the test with following options:
Number of threads: 8
Initializing random number generator from current time
Prime numbers limit: 10000
Initializing worker threads...
Threads started!
CPU speed:
events per second: 64490.28
General statistics:
total time: 30.0003s
total number of events: 1934753
Latency (ms):
min: 0.09
avg: 0.12
max: 21.01
95th percentile: 0.46
sum: 239149.80
Threads fairness:
events (avg/stddev): 241844.1250/1938.40
execution time (avg/stddev): 29.8937/0.01
root@faabf0fd5dcf:/#
$ docker context use colima-x64
colima-x64
Current context is now "colima-x64"
$ docker container run -it --rm --name debian-bullseye debian:bullseye /bin/bash
[...]
root@be6276f3da26:/# uname -a
Linux be6276f3da26 5.10.93-0-virt #1-Alpine SMP Thu, 27 Jan 2022 09:34:38 +0000 x86_64 GNU/Linux
root@be6276f3da26:/# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
root@be6276f3da26:/# sysbench cpu --cpu-max-prime=10000 --threads=8 --time=30 run
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
Running the test with following options:
Number of threads: 8
Initializing random number generator from current time
Prime numbers limit: 10000
Initializing worker threads...
Threads started!
CPU speed:
events per second: 1077.72
General statistics:
total time: 30.0053s
total number of events: 32340
Latency (ms):
min: 3.38
avg: 7.41
max: 37.02
95th percentile: 13.22
sum: 239622.11
Threads fairness:
events (avg/stddev): 4042.5000/46.19
execution time (avg/stddev): 29.9528/0.01
root@be6276f3da26:/#
x86_64 on ARM はやはり遅いか......
参考
blog.amedama.jp