封装成docker

This commit is contained in:
2025-12-30 09:12:42 +00:00
parent 32294ebec1
commit df74a5414b
3 changed files with 129 additions and 0 deletions

60
.dockerignore Normal file
View File

@@ -0,0 +1,60 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
*.egg-info/
dist/
build/
*.egg
# Virtual Environment
venv/
env/
ENV/
# IDE
.vscode/
.idea/
*.swp
*.swo
*~
# OS
.DS_Store
Thumbs.db
# Git
.git/
.gitignore
# Database
*.db
*.sqlite
*.sqlite3
instance/
# Logs
*.log
# Environment variables
.env
.env.local
# Node modules (if any)
node_modules/
# Cache
.cache/
.pytest_cache/
# Documentation
README.md
docs/
# Start script (not needed in container)
start.py
main.py
pyproject.toml
.python-version

38
Dockerfile Normal file
View File

@@ -0,0 +1,38 @@
# 使用官方Python运行时作为基础镜像
FROM python:3.11-slim
# 设置工作目录
WORKDIR /app
# 设置环境变量
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
FLASK_APP=app.py
# 安装系统依赖
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
&& rm -rf /var/lib/apt/lists/*
# 复制依赖文件
COPY backend/requirements.txt /app/backend/requirements.txt
# 安装Python依赖
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r /app/backend/requirements.txt
# 复制项目文件
COPY backend/ /app/backend/
COPY frontend/ /app/frontend/
# 创建数据目录
RUN mkdir -p /app/data
# 暴露端口
EXPOSE 5000
# 设置工作目录为backend
WORKDIR /app/backend
# 启动应用
CMD ["python", "app.py"]

31
docker-compose.yml Normal file
View File

@@ -0,0 +1,31 @@
version: '3.8'
services:
# Flask应用服务
app:
build:
context: .
dockerfile: Dockerfile
container_name: worklist-app
restart: unless-stopped
ports:
- "5000:5000"
environment:
- FLASK_APP=app.py
- FLASK_ENV=production
- PYTHONUNBUFFERED=1
- SECRET_KEY=${SECRET_KEY:-your-secret-key-here}
- OPENAI_API_KEY=${OPENAI_API_KEY:-}
volumes:
# 持久化数据库
- ./data:/app/data
- ./backend/instance:/app/backend/instance
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:5000/"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
volumes:
data: