搭建专属 API 中转代理(如 CLIProxyAPI Plus)可解决网络连通性及多账号管理问题。本文介绍基于 Docker 的灵活部署方案,详解端口与目录映射规则。
Docker 配置法则
在 docker-compose.yml 文件中,端口(ports)和文件目录(volumes)均使用冒号分隔:
- 端口:格式为
本地端口:容器端口。左侧为本地开放端口,右侧为程序内部固定端口(如 8317),切勿修改右侧。 - 目录:格式为
本地路径:容器路径。左侧为本地存储路径,右侧为容器内虚拟路径,切勿修改右侧。
安装 Docker 环境
- Linux 云服务器:运行
curl -fsSL https://get.docker.com | bash一键安装。 - Windows 本地电脑:下载并安装 Docker Desktop,启动后左下角显示绿灯即就绪。
Windows 本地部署实战
以 D:\AI-Proxy 目录为例(可替换为任意路径)。
1. 创建目录
以管理员身份运行 PowerShell,执行以下命令:
New-Item -ItemType Directory -Force -Path D:\AI-Proxy\auths
New-Item -ItemType Directory -Force -Path D:\AI-Proxy\logs
cd D:\AI-Proxy
2. 生成配置文件
继续运行以下命令生成 docker-compose.yml:
Set-Content -Path docker-compose.yml -Value @"
services:
cli-proxy-api:
image: eceasy/cli-proxy-api-plus:latest
container_name: cli-proxy-api-plus
ports:
- "9999:8317"
volumes:
- ./config.yaml:/CLIProxyAPI/config.yaml
- ./auths:/root/.cli-proxy-api
- ./logs:/CLIProxyAPI/logs
restart: unless-stopped
"@
3. 下载并修改配置
Invoke-WebRequest -Uri "https://raw.githubusercontent.com/router-for-me/CLIProxyAPIPlus/main/config.example.yaml" -OutFile "config.yaml"
notepad D:\AI-Proxy\config.yaml
4. 修改远程访问配置
编辑 config.yaml,确保包含以下内容:
allow-remote: true
secret-key: '你的访问密码'
5. 启动服务
docker compose pull && docker compose up -d
Linux 云服务器部署实战
以 ~/my-api-proxy 为例。






