-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
44 lines (35 loc) · 1.25 KB
/
Dockerfile
File metadata and controls
44 lines (35 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 使用官方 Python 3.12 slim 镜像作为基础镜像
FROM python:3.12-slim
# 设置工作目录
WORKDIR /app
# 设置环境变量 - OPTIMIZED for performance
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PYTHONOPTIMIZE=2 \
ASYNCIO_DEBUG=0
# 安装系统依赖(性能优化)
RUN apt-get update && apt-get install -y \
gcc \
g++ \
curl \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# 复制 requirements.txt 并安装 Python 依赖
COPY requirements.txt .
RUN pip install --upgrade pip --no-cache-dir && \
pip install -r requirements.txt --no-cache-dir
# 复制应用代码
COPY app/ ./app/
# 创建非 root 用户(安全最佳实践)
RUN useradd --create-home --shell /bin/bash app && \
chown -R app:app /app
USER app
# 暴露端口
EXPOSE 8000
# 健康检查 - 优化检查频率
HEALTHCHECK --interval=15s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/metrics || exit 1
# 运行应用的命令 - 性能优化配置
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "1", "--loop", "uvloop", "--backlog", "2048", "--limit-concurrency", "1000", "--limit-max-requests", "10000"]