AI Application DeploymentAI 应用部署

Deploy Open WebUI with Docker and Persistent Storage使用 Docker 和持久化存储部署 Open WebUI

Run Open WebUI in Docker, persist application data, connect it to Ollama and add the production safeguards recommended by the project documentation.使用 Docker 运行 Open WebUI、持久化应用数据、连接 Ollama,并补充官方文档建议的生产环境安全措施。

Difficulty 2/5难度 2/520 minutes20 分钟Linux with Docker; 2 CPU cores and 4 GB RAM is a practical UI starting point, excluding model inferenceLinux 与 Docker;仅运行界面可从 2 核 4GB 起步,不包含模型推理资源

Architecture

Open WebUI provides the browser interface while Ollama or another compatible backend provides model inference. They may run on the same host or separate hosts. Size the inference host for the model; size the Open WebUI host for users, uploads and application services.

Data and secrets

Mount /app/backend/data to persistent storage. The official quick start also recommends a persistent WEBUI_SECRET_KEY for production. Losing either can disrupt sessions or application data.

Image version policy

The main image is convenient for evaluation. For production, select and test a specific release tag, document it and upgrade deliberately after reading release notes.

Public access checklist

Keep the container port bound to a private interface when possible.
Use Caddy for HTTPS and a stable domain.
Disable public sign-up unless the service is intentionally open.
Back up the persistent volume before upgrades.
Keep Ollama private; expose Open WebUI rather than the raw model API.

Source

Confirm commands and environment variables in the official Open WebUI quick start before each upgrade.

系统结构

Open WebUI 提供浏览器界面,Ollama 或其他兼容后端负责模型推理。两者可以运行在同一主机,也可以分开部署。推理主机应按模型选择资源;Open WebUI 主机则按用户数量、上传文件和应用服务估算。

数据与密钥

必须将 /app/backend/data 挂载到持久化存储。官方快速入门还建议生产环境使用固定的 WEBUI_SECRET_KEY。丢失数据卷或密钥都可能影响会话与应用数据。

镜像版本策略

main 镜像适合快速体验。生产环境应选择并测试明确的发布标签,记录当前版本,并在阅读更新说明后有计划地升级。

公网访问检查

条件允许时,仅在私有接口绑定容器端口。
使用 Caddy 配置 HTTPS 和稳定域名。
除非明确提供公共服务,否则关闭公开注册。
每次升级前备份持久化数据卷。
保持 Ollama 仅内部访问,对外提供 Open WebUI,而不是原始模型 API。

资料来源

每次升级前,请在 Open WebUI 官方快速入门 中确认当前命令和环境变量。

Deployment steps部署步骤

01

Prepare Docker and persistent storage准备 Docker 与持久化存储

Confirm Docker is available. A named volume keeps application data outside the container lifecycle.

确认 Docker 可用。命名数据卷可以让应用数据独立于容器生命周期。

docker --version
docker volume create open-webui
02

Generate a stable application secret生成固定的应用密钥

Generate a long random value and store it in a root-readable environment file or secret manager. Reuse the same value after restarts and upgrades.

生成足够长的随机值,并保存到仅管理员可读的环境文件或密钥管理系统中。重启和升级后必须继续使用同一密钥。

openssl rand -hex 32
03

Start Open WebUI启动 Open WebUI

This evaluation command persists data and lets the container reach an Ollama service on the host. Replace the example secret and pin a tested image tag for production.

该体验命令会持久化数据,并允许容器访问宿主机上的 Ollama。请替换示例密钥;生产环境应固定经过测试的镜像标签。

docker run -d -p 127.0.0.1:3001:8080 --add-host=host.docker.internal:host-gateway -e OLLAMA_BASE_URL=http://host.docker.internal:11434 -e WEBUI_SECRET_KEY='replace-with-a-long-random-value' -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:main
04

Verify the container验证容器状态

Check container health and logs locally before connecting a domain or opening a firewall rule.

绑定域名或开放防火墙规则前,先在本机检查容器状态和日志。

docker ps --filter name=open-webui
docker logs --tail=100 open-webui
curl -I http://127.0.0.1:3001
05

Add Caddy and HTTPS配置 Caddy 与 HTTPS

Reverse proxy the local port through Caddy. Keep the container port private and confirm sign-up settings after creating the administrator.

通过 Caddy 反向代理本地端口,保持容器端口不直接对外,并在创建管理员后确认注册策略。

# openwebui.example.com {
#   reverse_proxy 127.0.0.1:3001
# }