使用 Colima 在 Apple Silicon 上运行 Oracle 容器镜像

在 Apple Silicon(M 系列)Mac 上部署 Oracle 容器存在架构兼容性难题。本教程介绍如何通过 Colima 配置 x86_64 虚拟机并启用 Rosetta 支持,轻松在 ARM macOS 上运行 Oracle 数据库镜像。
single

oracle 目前不支持 ARM 芯片,所以我们只能通过 colima 来在 ARM macOS 上运行 x86 容器。

Colima 是一个在 macOS 和 Linux 上运行 本地容器虚拟化环境 的工具,它的核心目标是:让你在 非 Linux 系统(特别是 macOS)上运行 Docker 或 containerd 容器,同时比 Docker Desktop 更轻量、更开源。

功能说明
运行 Docker 容器完全兼容 docker 命令(需要配合 Docker CLI)
支持 containerd也可以只用 containerd,适合 K8s 用户
ARM / x86 多架构支持在 ARM Mac 上运行 x86 容器(支持 Rosetta)
高性能挂载支持 virtiofs 挂载,比 sshfs 快得多
可配置资源自由设置 CPU、内存、磁盘、挂载点等
完全免费无许可证限制(对比 Docker Desktop)

安装 colima

$ brew install colima
$ brew install qemu
$ brew install lima-additional-guestagents

需要安装 qemulima-additional-guestagents,不然会报错:

$ colima start --memory 8 --arch x86_64
WARN[0000] Failed to resolve the guest agent binary for "x86_64"  error="guest agent binary could not be found for Linux-x86_64 (Hint: try installing `lima-additional-guestagents` package)"
WARN[0000] Failed to resolve the guest agent binary for "armv7l"  error="guest agent binary could not be found for Linux-armv7l (Hint: try installing `lima-additional-guestagents` package)"
WARN[0000] Failed to resolve the guest agent binary for "ppc64le"  error="guest agent binary could not be found for Linux-ppc64le (Hint: try installing `lima-additional-guestagents` package)"
WARN[0000] Failed to resolve the guest agent binary for "riscv64"  error="guest agent binary could not be found for Linux-riscv64 (Hint: try installing `lima-additional-guestagents` package)"
WARN[0000] Failed to resolve the guest agent binary for "s390x"  error="guest agent binary could not be found for Linux-s390x (Hint: try installing `lima-additional-guestagents` package)"

INFO[0000] starting colima                              
INFO[0000] runtime: docker                              
FATA[0003] error starting vm: qemu is required to emulate x86_64: qemu-img not found, run 'brew install qemu' to install

启动 colima

$ colima start --arch x86_64 --vm-type=vz --vz-rosetta

# 可以查看虚拟机情况
$ colima status
INFO[0000] colima is running using macOS Virtualization.Framework 
INFO[0000] arch: x86_64                                 
INFO[0000] runtime: docker                              
INFO[0000] mountType: virtiofs                          
INFO[0000] socket: unix:///Users/vitah/.colima/default/docker.sock
参数含义说明
colima start启动(或创建)一个 Colima 虚拟机实例会自动拉起 Docker 或 containerd 容器运行时环境
--arch x86_64设置虚拟机的 CPU 架构为 x86_64(也叫 amd64)适用于运行 仅支持 Intel 架构的容器(如 Oracle 数据库官方镜像)
--vm-type=vz使用 macOS 原生虚拟化框架 Virtualization.framework(简称 vz)相比默认的 QEMU 更快更省资源,仅 macOS 12+ 支持
--vz-rosetta启用 Rosetta 2 翻译支持,让 ARM Mac 能运行 x86_64 Linux 程序仅在使用 --vm-type=vz 且 Mac 是 Apple Silicon(M1/M2/M3)时有效

启动结果:

$ colima start --arch x86_64 --vm-type=vz --vz-rosetta

INFO[0000] starting colima                              
INFO[0000] runtime: docker                              
INFO[0002] creating and starting ...                     context=vm
INFO[0066] provisioning ...                              context=docker
INFO[0073] starting ...                                  context=docker
INFO[0163] done

oracle 镜像

接下来就是 docker 启动 oracle 镜像。

创建容器:

$ docker login

# 下载镜像
$ docker pull oracleinanutshell/oracle-xe-11g

# 启动容器
$ docker run -d --name oracle_11g -p 127.0.0.1:1521:1521 oracleinanutshell/oracle-xe-11g
# oracle的默认用户是system,密码是oracle

参考链接