Files

32 lines
962 B
Docker
Raw Permalink 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.
FROM python:3.12-slim
WORKDIR /app
# 安装系统依赖
RUN apt-get update && apt-get install -y \
gcc \
default-libmysqlclient-dev \
pkg-config \
&& rm -rf /var/lib/apt/lists/*
# 复制依赖文件
COPY requirements.txt .
# 安装Python依赖
RUN pip install --no-cache-dir -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
# 复制项目代码
COPY . .
# 暴露端口
EXPOSE 8000
# 启动命令 - 运行迁移、收集静态文件,并使用 Granian(Rust) 以 ASGI 接口启动
# Granian 性能远超 Daphne,原生支持 ASGI/WebSocket(Channels ProtocolTypeRouter)
# 注意:ASGI 接口下 blocking-threads 必须为 1(Granian 限制),并发由事件循环承担
CMD python manage.py migrate --noinput && \
python manage.py collectstatic --noinput && \
granian --interface asgi --host 0.0.0.0 --port 8000 \
--workers 2 --backlog 2048 \
--log-level info chunyu_project.asgi:application