Files
Scoring-System/backend/Dockerfile
爽哒哒 3ae9e6856d
All checks were successful
Deploy to Server / deploy (push) Successful in 18s
chore: 后端服务端口统一为 8876:8876
2026-03-18 23:07:19 +08:00

41 lines
1.1 KiB
Docker

# 使用 Python 3.12 slim 镜像作为基础镜像
FROM python:3.12-slim
# 设置环境变量
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PYTHONIOENCODING=utf-8
# 设置工作目录
WORKDIR /app
# 安装系统依赖
RUN apt-get update && apt-get install -y \
gcc \
libpq-dev \
libffi-dev \
libjpeg-dev \
zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*
# 复制 requirements 文件并安装依赖
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# 复制项目代码
COPY . .
# 创建媒体文件目录
RUN mkdir -p /app/media /app/static
# 暴露端口
EXPOSE 8876
# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -c "import requests; requests.get('http://localhost:8876/api/health/')" || exit 1
# 启动命令
CMD ["sh", "-c", "python manage.py collectstatic --noinput && python manage.py migrate && gunicorn --bind 0.0.0.0:8876 --workers 4 --threads 2 --worker-class gthread --access-logfile - --error-logfile - --capture-output --enable-stdio-inheritance config.wsgi:application"]