Files
Obsidian/工具相关/Docker-Copilot部署.md
T

116 lines
3.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Docker Copilot 部署与使用
> 版本:2.1.1(镜像 `0nlylty/dockercopilot:2.1.1`)
> 作用:网页管理所有 Docker 容器,一键更新到最新版,不用一个个敲命令。
---
## 一、安装(服务器上跑一条命令)
```bash
docker run -d \
--name dockercopilot \
-p 127.0.0.1:8080:12712 \
-v /var/run/docker.sock:/var/run/docker.sock \
-e secretKey=你自己定的密码 \
--restart unless-stopped \
0nlylty/dockercopilot:2.1.1
```
> 密码说明:`secretKey` 就是登录密码,你 2026-11-06 安装时设的那个。密码不要写进文档——这个面板能管服务器上所有容器,密码泄露等于整台服务器失守。记在密码管理器里(比如 Bitwarden),或者记在你自己的密码本上。
检查:
```bash
docker ps --filter 'name=dockercopilot' --format '{{.Status}} {{.Ports}}'
```
看到 `Up` 和 `127.0.0.1:8080->12712` 就是跑起来了。
---
## 二、两个坑(必看)
### 坑 1:必须设 `secretKey`
不设就直接 panic 崩溃,容器反复重启:
```
panic: secret's length can't be less than 8
```
要求:8 位以上,不能纯数字。这个值就是以后登录 Docker Copilot 的密码,第一次登录就用它。
### 坑 2:容器内监听 12712,不是 8080
日志里写着 `Starting server at 0.0.0.0:12712`。映射必须写成:
```
-p 127.0.0.1:8080:12712
```
写成 `8080:8080` 容器是 Up 的,但页面打不开。
---
## 三、访问
Docker Copilot 只绑了服务器本机 `127.0.0.1`,要走隧道:
**1. 开隧道**(新开一个 PowerShell 窗口,输密码,窗口保持开着):
```
ssh -N -L 8080:127.0.0.1:8080 ubuntu@服务器IP
```
**2. 浏览器开**:`http://localhost:8080`
**3. 登录框**:
- 网址:`localhost`
- 端口:`8080`
- 密钥:你设的 secretKey
点 OK 进去,能看到所有容器的列表。
---
## 四、用法
- **容器列表**:看每个容器的状态、版本、运行时间
- **更新**:有新版本时点「更新」,一键拉最新镜像重建容器
- **启动 / 停止 / 重启**:列表里直接点
- **备份**:可以备份容器配置
---
## 五、换台电脑 / 换台服务器用
1. 新服务器上装好 Docker
2. 跑上面「一、安装」那条命令(换个 secretKey 密码)
3. 隧道开 8080,浏览器开 `http://localhost:8080` 登录
域名反代(可选):想用域名访问、不用开隧道时,再配 Spaceship 解析 + 服务器反代,把域名转到 8080 端口。注意:域名 trivoo.website 注册和 DNS 都在 Spaceship,不在 Cloudflare,别走错地方。
## 六、域名反代(已配好,2026-11-06)
域名:**https://docker.trivoo.website**,登录时网址选 `https://`、端口填 `443`、密钥填 secretKey。
配法(下次照抄):
**1. DNS 解析(Spaceship)**:`trivoo.website` → Advanced DNS → 加一条 A 记录,Host `docker`,Value `43.156.118.130`,TTL 30 min。
**2. Nginx 反代(服务器上)**:新建 `/etc/nginx/sites-available/docker.trivoo.website`,照着 `api.trivoo.website` 的结构写,`proxy_pass` 改成 `http://127.0.0.1:8080`,只留 `listen 80`:
```bash
ln -s /etc/nginx/sites-available/docker.trivoo.website /etc/nginx/sites-enabled/
nginx -t && systemctl reload nginx
```
**3. 证书**:
```bash
certbot --nginx -d docker.trivoo.website
```
证书有效期到 2027-02-04,Certbot 已设自动续期。验证通过:浏览器打开域名能看到登录框,容器日志 `/api/containers` 全是 200。