当前位置: 首页 > news >正文

完整教程:机器学习入门,用Lima在macOS免费搭建Docker环境,彻底解决镜像与收费难题!

国内用户必看】用Lima在macOS免费搭建Docker环境,彻底解决镜像与收费难题!

为了在不同操作系统有一致操作体验,我选择使用docker技术安装ollama,这样子还有一个好处,即使玩坏了,删除重建即可,所以首先需要在开发机上安装docker,从2024年开始在国内使用docker难度越来越大,主要有2大原因:

  1. docker开始收费了,办公电脑公司不让在安装docker桌面版了
  2. docker国内镜像一夜之间都不能用了,docker官方镜像在国内也是无法访问的

下面是在 macOS 上使用 limactl 安装和配置 Docker 的完整步骤。这个方法比 Docker Desktop 更轻量且完全免费。

准备工作

确保你的 macOS 系统已更新到较新版本
确保已安装 Homebrew(macOS 包管理器)

lima&docker安装步骤

步骤 1: 安装 Lima

打开终端(Terminal),执行以下命令:

# 使用 Homebrew 安装 Lima
brew install lima
# 验证安装是否成功
limactl --version

步骤 2: 启动 Docker 实例

Lima 使用模板来创建预配置的虚拟机。我们将使用官方提供的 Docker 模板:

# 创建并启动一个名为 "docker" 的实例(使用非root用户模式,推荐)
limactl start --name=docker template://docker

注:除了可以使用官方模板也可以自定义配置文件,启动命令&配置文件&执行过程日志示例如下

# 与上面的命令 limactl start --name=docker template://docker 二选一执行即可
limactl start ~/work/docker/lima-default.yaml
arch: "aarch64"
# 基本系统配置
images:
- location: "https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-22.04-server-cloudimg-amd64.img"
arch: "x86_64"
- location: "https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-22.04-server-cloudimg-arm64.img"
arch: "aarch64"
# 系统配置脚本
provision:
- mode: system
script: |
#!/bin/bash
set -eux -o pipefail
# 安装 Docker
curl -fsSL https://get.docker.com | sh
# 将用户添加到 docker 组
usermod -aG docker "${LIMA_USER}"
# 安装 Docker Compose 插件
apt-get install -y docker-compose-plugin
# 挂载配置
mounts:
- location: "~"
mountPoint: "/home/${LIMA_USER}.linux"
# 端口转发(关键!让主机可以访问虚拟机内的 Docker)
portForwards:
- guestSocket: "/var/run/docker.sock"
hostSocket: "${LIMA_HOST_HOME}/.lima/docker/sock/docker.sock"
# 其他配置
ssh:
localPort: 60022
containerd:
system: false
user: false
? Creating an instance "docker" Proceed with the current configuration
INFO[0001] Replacing "http_proxy" value "socks5h://127.0.0.1:13659" with "socks5h://192.168.5.2:13659"
INFO[0001] Replacing "https_proxy" value "socks5h://127.0.0.1:13659" with "socks5h://192.168.5.2:13659"
INFO[0001] Starting the instance "docker" with VM driver "vz"
INFO[0001] Attempting to download the image              arch=aarch64 digest= location="https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-arm64.img"
INFO[0007] Using cache "/Users/mac/Library/Caches/lima/download/by-url-sha256/002fbe468673695a2206b26723b1a077a71629001a5b94efd8ea1580e1c3dd06/data"
INFO[0007] Converting "/Users/mac/.lima/docker/basedisk" (qcow2) to a raw disk "/Users/mac/.lima/docker/diffdisk"
3.50 GiB / 3.50 GiB [---------------------------------------] 100.00% 1.56 GiB/s
INFO[0009] Expanding to 100GiB
INFO[0010] Attempting to download the nerdctl archive    arch=aarch64 digest="sha256:544fa1e518155fcc01a117ea49819d12d96b4dacfb2b62922f9f7956dc9f6dc8" location="https://github.com/containerd/nerdctl/releases/download/v2.1.3/nerdctl-full-2.1.3-linux-arm64.tar.gz"
INFO[0010] Using cache "/Users/mac/Library/Caches/lima/download/by-url-sha256/46d9ee12c9f3f484518470db8093719f2b3ddca7daa6f1741c71e0aeb198db2a/data"
INFO[0010] [hostagent] Replacing "http_proxy" value "socks5h://127.0.0.1:13659" with "socks5h://192.168.5.2:13659"
INFO[0010] [hostagent] Replacing "https_proxy" value "socks5h://127.0.0.1:13659" with "socks5h://192.168.5.2:13659"
INFO[0010] [hostagent] Replacing "http_proxy" value "socks5h://127.0.0.1:13659" with "socks5h://192.168.5.2:13659"
INFO[0010] [hostagent] Replacing "https_proxy" value "socks5h://127.0.0.1:13659" with "socks5h://192.168.5.2:13659"
INFO[0011] [hostagent] hostagent socket created at /Users/mac/.lima/docker/ha.sock
INFO[0011] [hostagent] Starting VZ (hint: to watch the boot progress, see "/Users/mac/.lima/docker/serial*.log")
INFO[0012] SSH Local Port: 60022
INFO[0011] [hostagent] Waiting for the essential requirement 1 of 2: "ssh"
INFO[0011] [hostagent] [VZ] - vm state change: running
INFO[0021] [hostagent] Waiting for the essential requirement 1 of 2: "ssh"
INFO[0031] [hostagent] Waiting for the essential requirement 1 of 2: "ssh"
INFO[0041] [hostagent] Waiting for the essential requirement 1 of 2: "ssh"
INFO[0052] [hostagent] Waiting for the essential requirement 1 of 2: "ssh"
INFO[0062] [hostagent] Waiting for the essential requirement 1 of 2: "ssh"
INFO[0072] [hostagent] Waiting for the essential requirement 1 of 2: "ssh"
INFO[0082] [hostagent] Waiting for the essential requirement 1 of 2: "ssh"
INFO[0092] [hostagent] Waiting for the essential requirement 1 of 2: "ssh"
INFO[0102] [hostagent] Waiting for the essential requirement 1 of 2: "ssh"
INFO[0112] [hostagent] Waiting for the essential requirement 1 of 2: "ssh"
INFO[0122] [hostagent] Waiting for the essential requirement 1 of 2: "ssh"
INFO[0132] [hostagent] Waiting for the essential requirement 1 of 2: "ssh"
INFO[0142] [hostagent] Waiting for the essential requirement 1 of 2: "ssh"

这个过程会:

  1. 下载 Ubuntu 基础镜像
  2. 在虚拟机内自动安装 Docker、Docker Compose 和其他相关工具
  3. 配置文件共享和端口转发
  4. 可能需要几分钟时间,取决于你的网络速度

步骤 3: 配置 Shell 环境

安装完成后,需要设置环境变量,让 macOS 上的 Docker CLI 能够与 Lima 虚拟机中的 Docker 引擎通信:

# 将以下行添加到你的 shell 配置文件(~/.zshrc 或 ~/.bash_profile)
echo 'export DOCKER_HOST="unix://${HOME}/.lima/docker/sock/docker.sock"' >> ~/.bash_profile
# 使配置生效
source ~/.bash_profile

步骤 4: 验证安装

测试 Docker 是否正常工作:

# 检查 Docker 版本
docker --version
# 运行测试容器
docker run --rm hello-world
# 查看 Docker 系统信息
docker info

如果这些命令都能正常执行并返回信息,而没有报错说无法连接到 Docker 守护进程,那么就说明您的 Shell 环境已经配置成功!

总结

在这里插入图片描述

附加常用命令

limactl list
NAME STATUS SSH VMTYPE ARCH CPUS MEMORY DISK DIR
docker Stopped 127.0.0.1:60022 vz aarch64 4 4GiB 100GiB ~/.lima/docker
limactl delete docker
INFO[0000] The vz driver process seems already stopped
INFO[0000] The host agent process seems already stopped
INFO[0000] Removing *.pid *.sock *.tmp under "/Users/mac/.lima/docker"
INFO[0000] Deleted "docker" ("/Users/mac/.lima/docker")
limactl list
WARN[0000] No instance found. Run `limactl create` to create an instance.

ollama&Phi-3:mini安装步骤

这部分之前已经整理过了,详情见:https://alioo.blog.csdn.net/article/details/150591424

http://www.jsqmd.com/news/1005/

相关文章:

  • go语言中的基本数据类型
  • 实用指南:rsync +生产级 lsyncd 实时同步方案
  • 锁定Nvidia驱动版本
  • 第二十一章-sql 注入-union 联合注入 (1)
  • Android开发参考
  • 求出e的值
  • CSP-S模拟24
  • 今年CSP...
  • 实用指南:VGG改进(9):融合Axial Attention的VGG16架构
  • 0voice-2.1.1-io多路复用select/poll/epoll
  • Transformer与ViT
  • comfUI背后的技术——VAE - 实践
  • CCPC2023 秦皇岛 M. Inverted
  • 实用指南:Maven、Spring Boot、Spring Cloud以及它们的相互关系
  • 【57页PPT】智慧高效的方案智慧医院信息化整体规划设计方案(附下载方式)
  • WordPress开放嵌入自动发现功能中的XSS漏洞分析
  • 第二次软工作业
  • 20250921 模拟赛 T4 题解
  • 1.3 课前问题列表
  • NOIP 模拟赛十一
  • Proxy 库解析(四)
  • warm-flow 监听器对象获取问题
  • Hexo Butterfly 5.4 分页问题 YAML 错误 解决方法总结
  • FPGA硬件设计6 ZYNQ外围-HDMI、PCIE、SFP、SATA、FMC - 教程
  • js逆向:某Q音乐平台请求数据模拟生成
  • 第十一届中国大学生程序设计竞赛网络预选赛(CCPC Online 2025)
  • 完整教程:数据结构 栈和队列、树
  • 深入解析:【ubuntu】ubuntu中找不到串口设备问题排查
  • 酵母双杂交技术:高通量筛选的突破与不可忽视的三大局限性
  • ubuntu20.04测试cuda