Docker容器部署Ollama+DeepSeek
使用Ubuntu系统演示(容器打包后也可centos运行)
一、ubuntu设置清华源
在 Ubuntu 24.04以前,Ubuntu 的软件源配置文件使用传统的 One-Line-Style,路径为 /etc/apt/sources.list;
从 Ubuntu 24.04 开始,Ubuntu 的软件源配置文件变更为 DEB822 格式,路径为 /etc/apt/sources.list.d/ubuntu.sources
传统格式(/etc/apt/sources.list)
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-backports main restricted universe multiverse
# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb http://security.ubuntu.com/ubuntu/ noble-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ noble-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-proposed main restricted universe multiverse
DEB822 格式(/etc/apt/sources.list.d/ubuntu.sources)
Types: deb
URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
Suites: noble noble-updates noble-backports
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
# Types: deb-src
# URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
# Suites: noble noble-updates noble-backports
# Components: main restricted universe multiverse
# Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
Types: deb
URIs: http://security.ubuntu.com/ubuntu/
Suites: noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
# Types: deb-src
# URIs: http://security.ubuntu.com/ubuntu/
# Suites: noble-security
# Components: main restricted universe multiverse
# Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
# 预发布软件源,不建议启用
# Types: deb
# URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
# Suites: noble-proposed
# Components: main restricted universe multiverse
# Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
# # Types: deb-src
# # URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
# # Suites: noble-proposed
# # Components: main restricted universe multiverse
# # Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
根据系统版本,复制对应的配置,到指定路径中的配置文件中。
再apt-get update 更新软件包
二、安装docker
使用阿里云镜像,加速docker下载
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
安装好后,可以docker ps测试一下
三、用Docker拉取ollama镜像,并运行成容器。
如下是docker compose file
version: '3.3'
services:
ollama:
image: 'ollama:ollama' ##这里是从github仓库拉取ollama
#image: 'ollama/ollama:latest' ##这里是读取本地ollama镜像
environment:
- NVIDIA_VISIBLE_DEVICES=all
deploy:
resources:
reservations:
devices:
- driver: nvidia
capabilities: [gpu]
container_name: ollama
volumes:
- './data:/data'
ports:
- '11434:11434'
随便找个目录创建dokcer-compose.yml文件,并把上面代码复制进去。
然后docker compose up -d 运行
**注:**如果从github拉取失败,那就要自己百度如何访问github
这里我是在本地访问到仓库后,docker pull ollama 拉取的镜像
然后更改上面的 .yml 文件,让它读取本地Ollama镜像运行
三、进入ollama容器,下载deepseek模型
1、上面 .yml文件执行成功后,可通过docker ps查看容器
2、使用docker exec -it 6bc93cc4233a(容器id) bash ,进入容器后执行下面命令
`# 拉模型速度取决于网速
ollama pull deepseek-r1:1.5b
# 运行模型,进入终端,退出终端命令:/exit
ollama run deepseek-r1:1.5b
# 列出模型
ollama list
效果图: