镜像制作

This commit is contained in:
2025-11-24 11:50:15 +08:00
parent 12592c5a24
commit 07bd166257
53 changed files with 3822 additions and 2140 deletions

53
docker/Dockerfile.serv Normal file
View File

@@ -0,0 +1,53 @@
# 后端服务运行镜像
# 注意jar包需要在主机中先编译好
FROM eclipse-temurin:21-jre
# 设置环境变量
ENV LANG=C.UTF-8 \
LC_ALL=C.UTF-8 \
TZ=Asia/Shanghai
# 安装Python3和pip用于爬虫以及MySQL客户端用于配置更新
RUN apt-get update && \
apt-get install -y python3 python3-pip python3-venv netcat-traditional curl default-mysql-client && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# 创建应用目录
WORKDIR /app
# 创建必要的目录
RUN mkdir -p /app/config /app/logs /app/uploads /app/crawler
# 从主机复制已编译的jar包
COPY schoolNewsServ/admin/target/admin-1.0.0.jar /app/app.jar
# 复制爬虫脚本
COPY schoolNewsCrawler/ /app/crawler/
# 安装爬虫依赖根据requirements.txt
RUN cd /app/crawler && \
if [ -f requirements.txt ]; then \
echo "安装爬虫依赖..."; \
python3 -m pip install --no-cache-dir -r requirements.txt; \
else \
echo "警告: 未找到requirements.txt文件"; \
fi
# 复制默认配置文件(作为备份)
COPY schoolNewsServ/admin/src/main/resources/application.yml /app/config/application.yml.template
COPY schoolNewsServ/admin/src/main/resources/log4j2-spring.xml /app/config/log4j2-spring.xml.template
# 复制启动脚本
COPY schoolNewsServ/docker/start.sh /app/start.sh
RUN chmod +x /app/start.sh
# 暴露端口
EXPOSE 8081
# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:8081/schoolNewsServ/actuator/health || exit 1
# 启动应用
CMD ["/app/start.sh"]