1、Dockerfile
FROM dockerhub.com/herlly:latest AS build
RUN mkdir /src
COPY ./ /src/
RUN mvn -T 1C -f /src/abc/pom.xml package -Dmaven.compile.fork=true -Dmaven.test.skip=true
FROM dockerhub.com/jdk:latest
ARG DEPENDENCY=/src/abc/target
ARG app
ENV APP ${app}
RUN mkdir -p /opt/${app}
&& mkdir -p /logs/${app}
COPY --from=build ${DEPENDENCY}/${app}.jar /opt/${app}/
COPY ./docker-entrypoint.sh /
RUN chmod +x /docker-entrypoint.sh
WORKDIR /opt/${app}
EXPOSE 20880
VOLUME /logs/${app}
ENTRYPOINT ["/sbin/tini","--","/docker-entrypoint.sh"]
2、docker-entrypoint.sh
#!/bin/sh
cd /opt/${APP}
if [[ $# -lt 1 ]] || [[ "$1" == "--"* ]]; then
JAVA_OPTS=" -server -Xmn256m -Xss256k -Djava.security.egd=file:/dev/./urandom -XX:MaxRAMPercentage=80.0 -XX:+UseContainerSupport -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 "
exec java ${JAVA_OPTS} -jar ${APP}.jar "$@"
fi
exec "$@"
3、构建镜像
docker build --build-arg app=${project} -t ${project}:latest-f ${project}-dockerfile .
docker tag ${project}:latest dockerhub.com/${project}:laster
docker push dockerhub.com/${project}:test
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.e1idc.net