项目打包
This commit is contained in:
71
Dockerfile
Normal file
71
Dockerfile
Normal file
@@ -0,0 +1,71 @@
|
||||
# BigDataTool Docker镜像
|
||||
# 基于Python 3.9 Alpine镜像构建轻量级容器
|
||||
|
||||
# 使用官方Python 3.9 Alpine镜像作为基础镜像
|
||||
FROM python:3.9-alpine
|
||||
|
||||
# 设置维护者信息
|
||||
LABEL maintainer="BigDataTool Team"
|
||||
LABEL version="2.0"
|
||||
LABEL description="BigDataTool - 大数据查询比对工具容器化版本"
|
||||
|
||||
# 设置环境变量
|
||||
ENV PYTHONUNBUFFERED=1 \
|
||||
PYTHONDONTWRITEBYTECODE=1 \
|
||||
PIP_NO_CACHE_DIR=1 \
|
||||
PIP_DISABLE_PIP_VERSION_CHECK=1 \
|
||||
FLASK_HOST=0.0.0.0 \
|
||||
FLASK_PORT=5000
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
# 安装系统依赖
|
||||
# Alpine需要的构建工具和运行时库
|
||||
RUN apk add --no-cache \
|
||||
gcc \
|
||||
musl-dev \
|
||||
libffi-dev \
|
||||
openssl-dev \
|
||||
cargo \
|
||||
rust \
|
||||
&& apk add --no-cache --virtual .build-deps \
|
||||
build-base \
|
||||
python3-dev
|
||||
|
||||
# 复制requirements文件
|
||||
COPY requirements.txt .
|
||||
|
||||
# 安装Python依赖
|
||||
# 使用国内镜像源加速下载
|
||||
RUN pip install --no-cache-dir -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/
|
||||
|
||||
# 清理构建依赖以减小镜像大小
|
||||
RUN apk del .build-deps
|
||||
|
||||
# 复制应用代码
|
||||
COPY . .
|
||||
|
||||
# 创建必要的目录
|
||||
RUN mkdir -p logs && \
|
||||
chmod +x docker-entrypoint.sh || true
|
||||
|
||||
# 创建非root用户运行应用
|
||||
RUN addgroup -g 1001 -S appgroup && \
|
||||
adduser -u 1001 -S appuser -G appgroup
|
||||
|
||||
# 更改文件所有权
|
||||
RUN chown -R appuser:appgroup /app
|
||||
|
||||
# 切换到非root用户
|
||||
USER appuser
|
||||
|
||||
# 暴露端口
|
||||
EXPOSE 5000
|
||||
|
||||
# 健康检查
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
||||
CMD wget --no-verbose --tries=1 --spider http://localhost:5000/api/health || exit 1
|
||||
|
||||
# 设置启动命令
|
||||
CMD ["python", "app.py"]
|
Reference in New Issue
Block a user