📄 模板概述

Lima 使用 YAML 文件定义虚拟机配置。模板指定了操作系统、CPU、内存、磁盘、挂载点等。

📋 内置模板

# 列出所有内置模板
limactl start --list-templates

# 常用模板
template://default # Ubuntu + containerd
template://docker # Docker 引擎
template://k8s # Kubernetes
template://podman # Podman
template://alpine # Alpine Linux
template://fedora # Fedora
template://archlinux # Arch Linux

✏️ 自定义模板

创建自定义模板文件:

# my-vm.yaml
vmType: "vz" # 使用 Apple 虚拟化

images:
- location: "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-arm64.img"
arch: "aarch64"

cpus: 4
memory: "8GiB"
disk: "50GiB"

mounts:
- location: "~"
writable: false
- location: "/tmp/lima"
writable: true

portForwards:
- guestPort: 80
hostPort: 8080

provision:
- mode: system
script: |
#!/bin/bash
apt-get update && apt-get install -y git curl

🔧 关键配置项

  • vmType - 虚拟化类型:qemu 或 vz
  • cpus - CPU 核心数
  • memory - 内存大小
  • disk - 磁盘大小
  • mounts - 文件挂载配置
  • portForwards - 端口转发
  • provision - 初始化脚本

🔗 模板继承 (v1.1+)

基于现有模板创建自定义配置:

# custom.yaml
base:
- template://_images/ubuntu-lts
- template://_default/mounts

provision:
- mode: system
script: |
#!/bin/bash
apt-get install -y build-essential
← 上一页:容器运行下一页:网络配置 →