52 lines
1.4 KiB
Docker
52 lines
1.4 KiB
Docker
# 文件传输服务 Docker 镜像
|
|
FROM python:3.11-slim
|
|
|
|
# 设置工作目录
|
|
WORKDIR /app
|
|
|
|
# 设置环境变量
|
|
ENV PYTHONDONTWRITEBYTECODE=1
|
|
ENV PYTHONUNBUFFERED=1
|
|
ENV HOST=0.0.0.0
|
|
ENV PORT=8000
|
|
|
|
# 配置阿里云镜像源
|
|
RUN sed -i 's|http://deb.debian.org|http://mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources \
|
|
&& sed -i 's|http://security.debian.org|http://mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources
|
|
|
|
# 安装系统依赖
|
|
RUN apt-get update \
|
|
&& apt-get install -y --no-install-recommends \
|
|
curl \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# 复制requirements.txt并安装Python依赖
|
|
COPY requirements.txt .
|
|
RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ \
|
|
&& pip config set global.trusted-host mirrors.aliyun.com \
|
|
&& pip install --no-cache-dir --upgrade pip \
|
|
&& pip install --no-cache-dir -r requirements.txt
|
|
|
|
# 复制应用程序代码
|
|
COPY . .
|
|
|
|
# 创建上传目录并设置权限
|
|
RUN mkdir -p uploads \
|
|
&& chmod 755 uploads
|
|
|
|
# 创建非root用户
|
|
RUN groupadd -r appuser && useradd -r -g appuser appuser \
|
|
&& chown -R appuser:appuser /app
|
|
|
|
# 切换到非root用户
|
|
USER appuser
|
|
|
|
# 暴露端口
|
|
EXPOSE 8000
|
|
|
|
# 健康检查
|
|
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
|
|
CMD curl -f http://localhost:8000/ || exit 1
|
|
|
|
# 启动命令
|
|
CMD ["python", "app.py"] |