Files
urbanLifeline/docker/example/Dockerfile.base-serv
2025-12-28 18:30:17 +08:00

119 lines
3.6 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 \
PYTHONUNBUFFERED=1 \
PYTHONIOENCODING=UTF-8 \
PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple \
PIP_TRUSTED_HOST=pypi.tuna.tsinghua.edu.cn
# 安装系统依赖和工具
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
# Python环境
python3 \
python3-pip \
python3-venv \
python3-dev \
# 编译工具
build-essential \
# 网络和诊断工具
netcat-traditional \
curl \
wget \
dnsutils \
iputils-ping \
# 系统工具
procps \
htop \
vim \
less \
# 数据库客户端
default-mysql-client \
# 字体和图形库
fonts-liberation \
fonts-noto-color-emoji \
fonts-noto-cjk \
# Chrome依赖
libxss1 \
libx11-xcb1 \
libxcb1 \
libxcomposite1 \
libxcursor1 \
libxdamage1 \
libxi6 \
libxtst6 \
libnss3 \
libcups2 \
libxrandr2 \
libasound2t64 \
libatk1.0-0 \
libatk-bridge2.0-0 \
libpangocairo-1.0-0 \
libgtk-3-0 \
# 图片处理
libjpeg-dev \
zlib1g-dev \
libpng-dev \
# 其他依赖
libffi-dev \
libssl-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone
# 设置Python3为默认Python
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1 \
&& update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1
WORKDIR /app
# 配置pip使用清华源
RUN mkdir -p /etc/pip && \
echo "[global]" > /etc/pip/pip.conf && \
echo "index-url = https://pypi.tuna.tsinghua.edu.cn/simple" >> /etc/pip/pip.conf && \
echo "trusted-host = pypi.tuna.tsinghua.edu.cn" >> /etc/pip/pip.conf
# 安装常用Python工具和爬虫依赖
COPY schoolNewsCrawler/requirements.txt /tmp/requirements.txt
RUN echo "========================================" && \
echo "安装Python爬虫依赖到基础镜像" && \
echo "========================================" && \
# 直接安装依赖使用系统pip不升级以避免破坏系统
python3 -m pip install --no-cache-dir --break-system-packages -r /tmp/requirements.txt && \
# 清理缓存
python3 -m pip cache purge && \
# 验证安装
echo "" && \
echo "✅ 爬虫依赖安装完成" && \
python3 -m pip list | grep -E "(beautifulsoup4|crawl4ai|selenium|pydantic|requests|loguru)" && \
# 清理临时文件
rm -f /tmp/requirements.txt
# 创建应用目录结构
RUN mkdir -p /app/config /app/logs /app/uploads /app/crawler
# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8080/actuator/health || exit 1
# 镜像元数据
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"]