-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile
More file actions
executable file
·38 lines (29 loc) · 973 Bytes
/
Dockerfile
File metadata and controls
executable file
·38 lines (29 loc) · 973 Bytes
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
FROM python:3.9-slim
# 设置工作目录
WORKDIR /app
# 设置环境变量
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PORT=50721 \
PYTHONUSERBASE=/app/.local
# 安装依赖
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt \
-i https://pypi.tuna.tsinghua.edu.cn/simple \
--trusted-host pypi.tuna.tsinghua.edu.cn
# 复制应用代码
COPY run.py .
COPY app/ ./app/
# 创建非特权用户和必要的目录
RUN useradd -m -u 1000 appuser && \
mkdir -p images logs static config && \
chown -R appuser:appuser /app
# 切换到非特权用户
USER appuser
# 暴露端口
EXPOSE ${PORT}
# 健康检查(使用 Python,因为 slim 镜像没有 curl)
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:${PORT}/')" || exit 1
# 设置容器启动命令
CMD ["python", "-u", "run.py", "--env=production"]