简单记录一下Maven项目如何快速完成Dockerfile编写
源代码:src.zip
编写Dockerfile
xFROM maven:3-jdk-8 AS builder
LABEL MAINTAINER="你的名字"
COPY ./src.zip /usr/src/COPY ./settings.xml /root/.m2/settings.xml
WORKDIR /usr/src
RUN cd /usr/src; \ unzip src.zip; \ mvn -U clean package -Dmaven.test.skip=true
FROM openjdk:8-jre
LABEL MAINTAINER="你的名字"
COPY --from=builder /usr/src/target/你的项目.jar /你的项目.jar
EXPOSE 你的端口
CMD ["java","-jar","/你的项目.jar","你的参数..."]
由于国内访问Maven官方仓库过慢,我这里COPY了一份阿里云的settings.xml
xxxxxxxxxx <settings xmlns="http://maven.apache.org/SETTINGS/1.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 http://maven.apache.org/xsd/settings-1.2.0.xsd"> <pluginGroups> </pluginGroups> <proxies> </proxies> <servers> </servers> <mirrors> <mirror> <id>aliyunmaven</id> <mirrorOf>*</mirrorOf> <name>aliyun</name> <url>https://maven.aliyun.com/repository/public</url> </mirror> <mirror> <id>maven-default-http-blocker</id> <mirrorOf>external:http:*</mirrorOf> <name>Pseudo repository to mirror external repositories initially using HTTP.</name> <url>http://0.0.0.0/</url> <blocked>true</blocked> </mirror> </mirrors> <profiles> </profiles></settings>
按照这个模板,即可快速方便地build出一个Maven项目的image