解锁DeepSeek潜能:Docker+Ollama打造本地大模型部署新范式

L
DeepSeek AI 指南
Oct 8, 2025
10 分钟
All

一、引言

1、什么是 Docker

Docker:就像一个“打包好的 App”

想象一下,你写了一个很棒的程序,在自己的电脑上运行得很好。但当你把它发给别人,可能会遇到各种问题:

  • “这个软件需要 Python 3.8,但我只有 Python 3.6!”
  • “我没有你用的那个库,安装失败了!”
  • “你的程序要跑在 Linux,我的电脑是 Windows!”

💡 Docker 的作用:它就像一个“打包好的 App”,把你的软件、依赖、环境、系统配置等 全部封装到一个“容器” 里,别人拿到这个容器,就能直接运行,而不用关心它内部的细节。


🚀 把 Docker 想象成“集装箱”

传统运输 vs. 集装箱运输:

  • 以前(传统部署)
    • 货物(程序)需要不同的包装方式(运行环境)
    • 货物可能损坏(环境不兼容)
    • 装卸麻烦(程序迁移难)
  • 有了 Docker(容器部署)
    • 货物装进标准化集装箱(Docker 容器)
    • 不管运到哪里,集装箱里东西不变(程序环境一致)
    • 码头和船只可以直接装卸(轻松部署到不同系统)

Docker 让软件像“集装箱”一样标准化、可移植、易部署! 🚢

docker示意图

2、什么是 Ollama

Ollama 是一个本地运行大语言模型(LLM)的工具。 它可以让你在自己的电脑上直接运行 AI 模型,而不需要连接云端服务器。

💡 简单来说:Ollama 让你像运行普通软件一样,轻松在本地使用 ChatGPT、Llama、Mistral、Gemma 等大语言模型。

🚀 Ollama 的核心特点:

  1. 本地运行 🏠:不需要联网,保护隐私。
  2. 支持多种开源模型 📚:如 Llama 3、Mistral、Gemma 等。
  3. 易于安装和使用 🔧:几条命令即可运行。
  4. 轻量化优化 ⚡:支持 Mac、Linux、Windows 并支持 GPU 加速。
  5. 离线推理 🔒:完全本地,不依赖云端。
ollama界面

二、准备工作

1、操作系统

本教程使用 CentOS 7.9(4核8G)。也可以使用其他 Linux 发行版或 Windows。

2、镜像准备

提前准备好镜像:ollama/ollama,镜像较大,下载时间较长。

镜像下载

三、安装

1、安装 Docker

① 关闭防火墙:

systemctl stop firewalld && systemctl disable firewalld

② 关闭 SELinux:

setenforce 0

③ 更换 yum 源:

rm -f /etc/yum.repos.d/*
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all && yum makecache

④ 安装依赖:

yum install -y yum-utils device-mapper-persistent-data lvm2

⑤ 添加 Docker 源:

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

⑥ 安装 Docker:

yum install docker-ce -y

⑦ 配置镜像加速:

vim /etc/docker/daemon.json
{
  "registry-mirrors": ["https://registry.docker-cn.com"]
}
systemctl restart docker
systemctl enable docker

2、启动 Ollama 容器

docker run -d --name ollama -p 11434:11434 ollama/ollama

首次启动会自动下载 Ollama 运行环境。

3、拉取 DeepSeek 模型

docker exec -it ollama ollama pull deepseek-coder:33b

可根据配置选择不同大小的模型,例如 deepseek-coder:7bdeepseek-coder:33b

4、启动 DeepSeek

docker exec -it ollama ollama run deepseek-coder:33b

然后在本地浏览器访问:

http://localhost:11434

🎉 你现在就可以在本地使用 DeepSeek 模型啦!


💡 总结: 通过 Docker + Ollama,我们可以在本地快速运行大型语言模型,安全、私密、灵活!

返回列表