Files

48 lines
2.1 KiB
Docker
Raw Permalink 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.
# =============================================================
# freedom-admin 后端镜像
# 构建阶段:Maven 3.6.3 + JDK8 打包(使用阿里云镜像加速依赖下载)
# 运行阶段:JRE8 运行 jar
# =============================================================
FROM maven:3.6.3-jdk-8 AS builder
WORKDIR /build
# 配置 Maven 国内镜像源,加速依赖下载
RUN mkdir -p /root/.m2 && \
echo '<?xml version="1.0" encoding="UTF-8"?>' > /root/.m2/settings.xml && \
echo '<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"' >> /root/.m2/settings.xml && \
echo ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' >> /root/.m2/settings.xml && \
echo ' xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">' >> /root/.m2/settings.xml && \
echo ' <mirrors>' >> /root/.m2/settings.xml && \
echo ' <mirror>' >> /root/.m2/settings.xml && \
echo ' <id>aliyun</id>' >> /root/.m2/settings.xml && \
echo ' <mirrorOf>central</mirrorOf>' >> /root/.m2/settings.xml && \
echo ' <name>Aliyun Maven</name>' >> /root/.m2/settings.xml && \
echo ' <url>https://maven.aliyun.com/repository/central</url>' >> /root/.m2/settings.xml && \
echo ' </mirror>' >> /root/.m2/settings.xml && \
echo ' </mirrors>' >> /root/.m2/settings.xml && \
echo '</settings>' >> /root/.m2/settings.xml
# 复制 pom 与源码(利用 Docker 分层缓存)
COPY pom.xml .
COPY src ./src
# 打包(跳过测试),产物 target/freedom-admin-1.0.1.jar
RUN mvn -B clean package -DskipTests
# ---------- 运行阶段 ----------
FROM openjdk:8-jre-slim
WORKDIR /app
# 设置时区
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo 'Asia/Shanghai' > /etc/timezone
# 复制构建产物
COPY --from=builder /build/target/*.jar /app/app.jar
# 对外暴露端口(与 application.yml server.port 一致)
EXPOSE 8800
# 启动。数据库等敏感配置通过环境变量注入(见 docker-compose / .env)
ENTRYPOINT ["java", "-jar", "/app/app.jar"]