当前位置: 首页 > 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: systemscript: |#!/bin/bashset -eux -o pipefail# 安装 Dockercurl -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: falseuser: 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/dockerlimactl 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://54PMqmA5.qpqwd.cn
http://Z63uJjpN.qpqwd.cn
http://3yYmZHD5.qpqwd.cn
http://wEJtTfTV.qpqwd.cn
http://MUAYaexR.qpqwd.cn
http://dDbRwhsX.qpqwd.cn
http://hDvwTNlS.qpqwd.cn
http://6bFdVQ3o.qpqwd.cn
http://jBhv6T4P.qpqwd.cn
http://g0bAY5HQ.qpqwd.cn
http://CbwArvln.qpqwd.cn
http://Rn2Q8yAo.qpqwd.cn
http://7J3PkViv.qpqwd.cn
http://I4YqU52N.qpqwd.cn
http://4vQGEsp6.qpqwd.cn
http://PYrOzP4B.qpqwd.cn
http://UJnJo4HZ.qpqwd.cn
http://YFLuDPdo.qpqwd.cn
http://fg0LzkWU.qpqwd.cn
http://x0EJ50aE.qpqwd.cn
http://vnrX1qIx.qpqwd.cn
http://IPlEIgCp.qpqwd.cn
http://x7mA8srH.qpqwd.cn
http://7IR0Ha3O.qpqwd.cn
http://m38TdALZ.qpqwd.cn
http://842KpXcW.qpqwd.cn
http://unddqeH7.qpqwd.cn
http://u0HQZVHO.qpqwd.cn
http://g7Hddzud.qpqwd.cn
http://OvMkeq9Z.qpqwd.cn
http://www.dtcms.com/a/368706.html

相关文章:

  • 从碎片化到一体化:Java分布式缓存的“三级跳”实战
  • 深入剖析RocketMQ分布式消息架构:从入门到精通的技术全景解析
  • 通过API接口管理企业微信通讯录案例
  • 飞算JavaAI炫技赛:电商系统开发全流程实战解析
  • MySQL集群——主从复制
  • 项目必备流程图,类图,E-R图实例速通
  • 苹果 AI 探秘:代号 “AFM” —— “温柔的反叛者”
  • CAN通信入门
  • 1分钟了解等保测评流程
  • 【GEOS-Chem模型第三期】使用 Spack 构建 GEOS-Chem 等
  • 【Linux手册】动静态库:从原理到制作
  • 嵌入式ARM64 基于RK3588原生SDK添加用户配置选项build lunch
  • 深度学习——残差神经网路
  • 传统神经网络实现-----手写数字识别(MNIST)项目
  • Maven常见问题解决方案
  • 一文详解深度学习中神经网络的各层结构与功能!
  • Java全栈开发工程师面试实录:从基础到实战的深度探讨
  • Unity打包Android应用常见问题解决指南
  • Snow Shot(截图工具) v0.2.6
  • LeNet-5:手写数字识别经典CNN
  • C++ opencv RTSP小工具 RTSP流播放、每一帧保存
  • android View详解—动画
  • 2024年9月GESPC++三级真题解析(含视频)
  • ASP.NET Core文件分片上传
  • OCA、OCP、OCM傻傻分不清?Oracle认证就看这篇
  • 面试了一个外包公司,面试不到5分钟就出来,这问题问得有点变态。。。。。。
  • Matlab使用小技巧合集(系列四):Table类型高效用法与数据处理实战
  • 25高教社杯数模国赛【C题超高质量思路+可运行代码】第十弹
  • WinForms 项目里生成时选择“首选目标平台 32 位导致有些电脑在获取office word对象时获取不到
  • ANSYS 热力耦合计算