This commit is contained in:
2026-04-27 01:25:45 +08:00
parent 5ec4c38495
commit b00a0c40d8
3 changed files with 52 additions and 0 deletions

13
.dockerignore Normal file
View File

@@ -0,0 +1,13 @@
# 构建镜像时不打进上下文(减小体积;数据在宿主机卷里)
.git
.env
.env.*
*.session
*.session-journal
state.json
-100*/
__pycache__
*.pyc
.cursor
.venv
venv

22
Dockerfile Normal file
View File

@@ -0,0 +1,22 @@
# 运行 Web 控制台;抓取数据通过卷挂载到 /data见 docker-compose 说明
FROM python:3.11-slim
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1
WORKDIR /app
RUN apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates \
&& rm -rf /var/lib/apt/lists/*
COPY requirements.txt .
RUN pip install --no-cache-dir -U pip setuptools wheel \
&& pip install --no-cache-dir -r requirements.txt
COPY telegram-scraper.py app_web.py ./
COPY templates ./templates/
EXPOSE 8000
CMD ["uvicorn", "app_web:app", "--host", "0.0.0.0", "--port", "8000"]

17
docker-compose.yml Normal file
View File

@@ -0,0 +1,17 @@
# 用法(在项目根目录):
# docker compose build
# docker compose up -d
# 数据持久化:把宿主机上的项目目录挂到 /data与 app 内工作目录一致(见下方 volumes
services:
web:
build: .
image: telegram-scraper-web:local
container_name: telegram-scraper-web
restart: unless-stopped
ports:
- "8000:8000"
working_dir: /data
volumes:
# 改成你服务器上「已有代码 + .env + state + session + 各 -100* 目录」的绝对路径
- ${HOST_PROJECT_DIR:-.}:/data
command: ["uvicorn", "app_web:app", "--host", "0.0.0.0", "--port", "8000"]