Skip to main content

TeleBox 一键 Docker 安装文档

· 4 min read
Mo
Software Engineer

本安装方案实现:

  • 首次登录一次性输入验证码
  • 之后完全一键启动,不再登录
  • 代码自动 clone / update
  • 数据与 session 持久化

本文档包含完整的 docker-compose.yml、目录结构、使用步骤。


📁 1. 创建目录结构

在任意安装目录执行:

mkdir -p telebox-config telebox-session telebox-assets telebox-plugins telebox-logs telebox-temp

📄 2. 创建 config.json

编辑:

nano telebox-config/config.json

内容示例:

{
"api_id": 123456,
"api_hash": "your_api_hash_here"
}

登录时会自动生成 session,因此这里不要加 session 字段


📦 3. 使用下方最终版 docker-compose.yml

将以下内容保存为 compose.yml

services:
telebox:
container_name: telebox
image: node:20-bookworm
working_dir: /opt/telebox/app
restart: unless-stopped
environment:
- TZ=Asia/Shanghai
- TB_PREFIX=. 。
- TB_SUDO_PREFIX=# $
- TB_CMD_IGNORE_EDITED=false
- TB_LISTENER_HANDLE_EDITED=sudo sure

volumes:
- ./telebox-config/config.json:/opt/telebox/vol/config.json
- ./telebox-session:/opt/telebox/vol/my_session
- ./telebox-assets:/opt/telebox/vol/assets
- ./telebox-plugins:/opt/telebox/vol/plugins
- ./telebox-logs:/opt/telebox/vol/logs
- ./telebox-temp:/opt/telebox/vol/temp

user: "0:0"

command: >
bash -lc "
set -e;
apt-get update &&
apt-get install -y --no-install-recommends git ca-certificates &&
rm -rf /var/lib/apt/lists/* &&
mkdir -p /opt/telebox/app /opt/telebox/vol &&
if [ ! -d /opt/telebox/app/.git ]; then
echo '>> Cloning TeleBox...';
git clone https://github.com/TeleBoxOrg/TeleBox.git /opt/telebox/app;
else
echo '>> Updating TeleBox...';
cd /opt/telebox/app && git pull;
fi &&
cd /opt/telebox/app &&

if [ -f /opt/telebox/vol/config.json ] && [ ! -e config.json ]; then ln -s /opt/telebox/vol/config.json config.json; fi &&
if [ -d /opt/telebox/vol/my_session ] && [ ! -e my_session ]; then ln -s /opt/telebox/vol/my_session my_session; fi &&
if [ -d /opt/telebox/vol/assets ] && [ ! -e assets ]; then ln -s /opt/telebox/vol/assets assets; fi &&
if [ -d /opt/telebox/vol/plugins ] && [ ! -e plugins ]; then ln -s /opt/telebox/vol/plugins plugins; fi &&
if [ -d /opt/telebox/vol/logs ] && [ ! -e logs ]; then ln -s /opt/telebox/vol/logs logs; fi &&
if [ -d /opt/telebox/vol/temp ] && [ ! -e temp ]; then ln -s /opt/telebox/vol/temp temp; fi &&

echo '>> Installing npm dependencies...';
npm install &&
echo '>> Starting TeleBox...';
npm run start
"

telebox-login:
image: node:20-bookworm
working_dir: /opt/telebox/app
stdin_open: true
tty: true
environment:
- TZ=Asia/Shanghai

volumes:
- ./telebox-config/config.json:/opt/telebox/vol/config.json
- ./telebox-session:/opt/telebox/vol/my_session
- ./telebox-assets:/opt/telebox/vol/assets
- ./telebox-plugins:/opt/telebox/vol/plugins
- ./telebox-logs:/opt/telebox/vol/logs
- ./telebox-temp:/opt/telebox/vol/temp

user: "0:0"

command: >
bash -lc "
set -e;
apt-get update &&
apt-get install -y --no-install-recommends git ca-certificates &&
rm -rf /var/lib/apt/lists/* &&
mkdir -p /opt/telebox/app /opt/telebox/vol &&
if [ ! -d /opt/telebox/app/.git ]; then
echo '>> Cloning TeleBox...';
git clone https://github.com/TeleBoxOrg/TeleBox.git /opt/telebox/app;
else
echo '>> Updating TeleBox...';
cd /opt/telebox/app && git pull;
fi &&
cd /opt/telebox/app &&

if [ -f /opt/telebox/vol/config.json ] && [ ! -e config.json ]; then ln -s /opt/telebox/vol/config.json config.json; fi &&
if [ -d /opt/telebox/vol/my_session ] && [ ! -e my_session ]; then ln -s /opt/telebox/vol/my_session my_session; fi &&
if [ -d /opt/telebox/vol/assets ] && [ ! -e assets ]; then ln -s /opt/telebox/vol/assets assets; fi &&
if [ -d /opt/telebox/vol/plugins ] && [ ! -e plugins ]; then ln -s /opt/telebox/vol/plugins plugins; fi &&
if [ -d /opt/telebox/vol/logs ] && [ ! -e logs ]; then ln -s /opt/telebox/vol/logs logs; fi &&
if [ -d /opt/telebox/vol/temp ] && [ ! -e temp ]; then ln -s /opt/telebox/vol/temp temp; fi &&

echo '>> Installing npm dependencies...';
npm install &&
echo '>> Starting TeleBox for FIRST LOGIN...';
npm run start
"

🔑 4. 进行第一次登录(必须做一次)

docker compose run --rm telebox-login

进入交互界面后按提示输入:

  1. 你的 Telegram 手机号
  2. 收到的 验证码
  3. (如果设置过)2FA 密码

出现登录成功提示后按:

CTRL + C

退出即可。

会话已经写入 ./telebox-session,以后永远不需要再次登录。


🚀 5. 启动正式服务

docker compose up -d telebox

查看运行日志:

docker logs -f telebox

若 bot 正常上线,则安装完成。


🔄 6. 更新 TeleBox(可选)

以后只需:

docker compose down
docker compose up -d

容器会自动执行 git pull + 更新依赖。


🎉 安装完成!

如需继续优化:

  • 加健康检查
  • 自动重启保护
  • 日志分离
  • 多账号共存

告诉我即可,我可以继续帮你完善配置。