Files
schoolNews/docker/Dockerfile.base-serv
2025-11-26 14:13:17 +08:00

62 lines
2.0 KiB
Docker
Raw 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.

# ====================================
# 后端基础镜像 - Base Serv
# 包含JRE + Python + 系统工具 + 爬虫依赖
# 用途:作为后端服务镜像的基础,避免每次都安装依赖
# ====================================
FROM eclipse-temurin:21-jre
# 设置环境变量
ENV LANG=C.UTF-8 \
LC_ALL=C.UTF-8 \
TZ=Asia/Shanghai
# 安装系统依赖和工具
RUN apt-get update && \
apt-get install -y \
# Python环境
python3 \
python3-pip \
python3-venv \
# 网络和诊断工具
netcat-traditional \
curl \
wget \
# MySQL客户端
default-mysql-client \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# 临时复制requirements.txt用于安装依赖
COPY schoolNewsCrawler/requirements.txt /tmp/requirements.txt
# 安装Python爬虫依赖一次性安装到基础镜像
RUN echo "========================================" && \
echo "安装Python爬虫依赖到基础镜像" && \
echo "========================================" && \
# 配置pip使用国内镜像源清华源
python3 -m pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \
python3 -m pip --version && \
echo "" && \
# Python 3.12 引入了 PEP 668 规范,需要添加 --break-system-packages
python3 -m pip install --no-cache-dir --break-system-packages -r /tmp/requirements.txt && \
echo "" && \
echo "✅ 爬虫依赖安装完成" && \
python3 -m pip list | grep -E "(beautifulsoup4|crawl4ai|selenium|pydantic|requests|loguru)" && \
# 清理临时文件
rm -f /tmp/requirements.txt
# 创建应用目录结构
WORKDIR /app
RUN mkdir -p /app/config /app/logs /app/uploads /app/crawler
# 镜像元数据
LABEL maintainer="School News Team" \
description="Base image for school-news backend service with Python dependencies" \
version="1.0"
# 暴露端口(文档用途)
EXPOSE 8081
# 默认命令(会被子镜像覆盖)
CMD ["echo", "This is base image, please use school-news-serv image"]